Commit 0862b6ae authored by Julien Muchembled's avatar Julien Muchembled

Many fixes in testInvoice

In particular, merge patches from testERP5Simulation.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@38139 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8afc48e1
......@@ -35,8 +35,8 @@ import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from testPackingList import TestPackingList, TestPackingListMixin
from testInvoice import TestSaleInvoice, TestInvoiceMixin
from testPackingList import TestPackingListMixin
from testInvoice import TestInvoiceMixin
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from Products.ERP5Type.Document.BusinessTemplate import getChainByType
......@@ -49,73 +49,6 @@ class TestERP5SimulationMixin(TestInvoiceMixin):
pay_business_link.setSource('account_module/bank')
pay_business_link.setDestination('account_module/bank')
@UnrestrictedMethod
def createInvoiceTransactionRule(self, resource=None):
"""Create a sale invoice transaction rule with only one cell for
product_line/apparel and default_region
The accounting rule cell will have the provided resource, but this his more
or less optional (as long as price currency is set correctly on order)
"""
portal = self.portal
account_module = portal.account_module
for account_id, account_gap, account_type \
in self.account_definition_list:
if not account_id in account_module.objectIds():
account = account_module.newContent(id=account_id)
account.setGap(account_gap)
account.setAccountType(account_type)
portal.portal_workflow.doActionFor(account, 'validate_action')
invoice_rule = portal.portal_rules.new_invoice_transaction_simulation_rule
if invoice_rule.getValidationState() == 'validated':
invoice_rule.invalidate()
invoice_rule.deleteContent(list(invoice_rule.contentIds(filter={'portal_type':['Predicate', 'Accounting Rule Cell']})))
transaction.commit()
self.tic()
region_predicate = invoice_rule.newContent(portal_type = 'Predicate')
product_line_predicate = invoice_rule.newContent(portal_type = 'Predicate')
region_predicate.edit(
membership_criterion_base_category_list = ['destination_region'],
membership_criterion_category_list =
['destination_region/region/%s' % self.default_region ],
int_index = 1,
string_index = 'region'
)
product_line_predicate.edit(
membership_criterion_base_category_list = ['product_line'],
membership_criterion_category_list =
['product_line/apparel'],
int_index = 1,
string_index = 'product'
)
product_line_predicate.immediateReindexObject()
region_predicate.immediateReindexObject()
invoice_rule.updateMatrix()
cell_list = invoice_rule.getCellValueList(base_id='movement')
self.assertEquals(len(cell_list),1)
cell = cell_list[0]
for line_id, line_source_id, line_destination_id, line_ratio in \
self.transaction_line_definition_list:
line = cell.newContent(id=line_id,
portal_type='Accounting Transaction Line', quantity=line_ratio,
resource_value=resource,
source_value=account_module[line_source_id],
destination_value=account_module[line_destination_id])
invoice_rule.validate()
transaction.commit()
self.tic()
def validateNewRules(self):
# create an Order Rule document.
portal_rules = self.portal.portal_rules
new_order_rule = filter(
lambda x:x.title == 'New Default Order Root Simulation Rule',
portal_rules.objectValues(portal_type='Order Root Simulation Rule'))[0]
if new_order_rule.getValidationState() != 'validated':
new_order_rule.validate()
class TestERP5Simulation(TestERP5SimulationMixin, ERP5TypeTestCase):
run_all_test = 1
quiet = 0
......@@ -277,52 +210,7 @@ class TestERP5Simulation(TestERP5SimulationMixin, ERP5TypeTestCase):
sequence_list.play(self, quiet=quiet)
class TestERP5SimulationInvoice(TestERP5SimulationMixin, TestSaleInvoice):
quiet = TestSaleInvoice.quiet
def test_09_InvoiceChangeStartDateFail(self, quiet=quiet):
"""
Change the start_date of a Invoice Line,
check that the invoice is divergent,
then accept decision, and check Packing list is *not* divergent,
because Unify Solver does not propagage the change to the upper
simulation movement.
"""
if not quiet:
self.logMessage('Invoice Change Sart Date')
sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
"""
stepSetReadyPackingList
stepTic
stepStartPackingList
stepCheckInvoicingRule
stepCheckInvoiceTransactionRule
stepTic
stepCheckInvoiceBuilding
stepChangeInvoiceStartDate
stepCheckInvoiceIsDivergent
stepCheckInvoiceIsCalculating
stepTic
stepCheckInvoiceIsDiverged
stepUnifyStartDateWithDecisionInvoice
stepTic
stepCheckInvoiceNotSplitted
stepCheckInvoiceIsNotDivergent
stepCheckInvoiceIsSolved
stepCheckPackingListIsNotDivergent
stepCheckPackingListIsSolved
stepCheckInvoiceTransactionRule
stepRebuildAndCheckNothingIsCreated
stepCheckInvoicesConsistency
"""
self.playSequence(sequence, quiet=quiet)
class TestAutomaticSolvingPackingList(TestERP5SimulationMixin, TestPackingListMixin,
ERP5TypeTestCase):
class TestAutomaticSolvingPackingList(TestPackingListMixin, ERP5TypeTestCase):
quiet = 0
def afterSetUp(self, quiet=1, run=1):
......@@ -424,7 +312,5 @@ class TestAutomaticSolvingPackingList(TestERP5SimulationMixin, TestPackingListMi
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Simulation))
suite.addTest(unittest.makeSuite(TestERP5SimulationPackingList))
suite.addTest(unittest.makeSuite(TestERP5SimulationInvoice))
suite.addTest(unittest.makeSuite(TestAutomaticSolvingPackingList))
return suite
......@@ -42,10 +42,8 @@ from Acquisition import aq_parent
from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
from testPackingList import TestPackingListMixin
from testAccountingRules import TestAccountingRulesMixin
class TestInvoiceMixin(TestPackingListMixin,
TestAccountingRulesMixin,):
class TestInvoiceMixin(TestPackingListMixin):
"""Test methods for invoices
"""
default_region = "europe/west/france"
......@@ -120,21 +118,12 @@ class TestInvoiceMixin(TestPackingListMixin,
def afterSetUp(self):
self.createCategories()
self.validateRules()
self.createBusinessProcess()
self.login()
self.oldMailHost = getattr(self.portal, 'MailHost', None)
if self.oldMailHost is not None:
self.portal.manage_delObjects(['MailHost'])
self.portal._setObject('MailHost', DummyMailHost('MailHost'))
transaction.commit()
self.tic()
def beforeTearDown(self):
transaction.abort()
self.tic()
# restore the original MailHost
if self.oldMailHost is not None:
self.portal.manage_delObjects(['MailHost'])
self.portal._setObject('MailHost', DummyMailHost('MailHost'))
super(TestInvoiceMixin, self).beforeTearDown()
for folder in (self.portal.accounting_module,
self.portal.organisation_module,
self.portal.sale_order_module,
......@@ -142,9 +131,7 @@ class TestInvoiceMixin(TestPackingListMixin,
self.portal.sale_packing_list_module,
self.portal.purchase_packing_list_module,
self.portal.portal_simulation,):
folder.manage_delObjects([x for x in folder.objectIds() if x not in ('organisation_1','organisation_2','ppl_1','ppl_2')])
transaction.commit()
self.tic()
......@@ -156,68 +143,44 @@ class TestInvoiceMixin(TestPackingListMixin,
user = uf.getUserById('test_invoice_user').__of__(uf)
newSecurityManager(None, user)
def stepCreateSaleInvoiceTransactionRule(self, sequence, **kw) :
"""Create the rule for accounting. """
self.createInvoiceTransactionRule(resource=sequence.get('resource'))
## XXX move this to "Sequence class"
def playSequence(self, sequence_string, quiet=0) :
sequence_list = SequenceList()
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
@UnrestrictedMethod
def createInvoiceTransactionRule(self, resource=None):
"""Create a sale invoice transaction rule with only one cell for
product_line/apparel and default_region
The accounting rule cell will have the provided resource, but this his more
or less optional (as long as price currency is set correctly on order)
"""
def createBusinessProcess(self):
portal = self.portal
account_module = portal.account_module
for account_id, account_gap, account_type \
in self.account_definition_list:
if not account_id in account_module.objectIds():
account = account_module.newContent(id=account_id)
account.setGap(account_gap)
account.setAccountType(account_type)
portal.portal_workflow.doActionFor(account, 'validate_action')
invoice_rule = portal.portal_rules.default_invoice_transaction_simulation_rule
if invoice_rule.getValidationState() == 'validated':
invoice_rule.invalidate()
invoice_rule.deleteContent(list(invoice_rule.objectIds()))
transaction.commit()
self.tic()
region_predicate = invoice_rule.newContent(portal_type = 'Predicate')
product_line_predicate = invoice_rule.newContent(portal_type = 'Predicate')
region_predicate.edit(
membership_criterion_base_category_list = ['destination_region'],
membership_criterion_category_list =
['destination_region/region/%s' % self.default_region ],
int_index = 1,
string_index = 'region'
)
product_line_predicate.edit(
membership_criterion_base_category_list = ['product_line'],
membership_criterion_category_list =
['product_line/apparel'],
int_index = 1,
string_index = 'product'
)
product_line_predicate.immediateReindexObject()
region_predicate.immediateReindexObject()
invoice_rule.updateMatrix()
cell_list = invoice_rule.getCellValueList(base_id='movement')
self.assertEquals(len(cell_list),1)
cell = cell_list[0]
for line_id, line_source_id, line_destination_id, line_ratio in \
self.transaction_line_definition_list:
line = cell.newContent(id=line_id,
portal_type='Accounting Transaction Line', quantity=line_ratio,
resource_value=resource,
business_process_id = self.__class__.__name__
try:
business_process = portal.business_process_module[business_process_id]
except KeyError:
business_process = portal.business_process_module.newContent(
business_process_id, 'Business Process',
specialise=self.__class__.business_process)
kw = dict(portal_type='Trade Model Path',
trade_phase='default/accounting',
trade_date='trade_phase/default/invoicing',
membership_criterion_base_category_list=('destination_region',
'product_line'),
membership_criterion_category=(
'destination_region/region/' + self.default_region,
'product_line/apparel'))
account_module = portal.account_module
for account_id, account_gap, account_type in self.account_definition_list:
if not account_module.has_key(account_id):
account = account_module.newContent(account_id, gap=account_gap,
account_type=account_type)
portal.portal_workflow.doActionFor(account, 'validate_action')
for line_id, line_source_id, line_destination_id, line_ratio in \
self.transaction_line_definition_list:
business_process.newContent(
reference='accounting_' + line_id,
efficiency=line_ratio,
source_value=account_module[line_source_id],
destination_value=account_module[line_destination_id])
invoice_rule.validate()
transaction.commit()
self.tic()
destination_value=account_module[line_destination_id],
**kw)
self.business_process = business_process.getRelativeUrl()
def stepCreateEntities(self, sequence, **kw) :
"""Create a vendor and two clients. """
......@@ -727,7 +690,7 @@ class TestInvoiceMixin(TestPackingListMixin,
portal_type=self.invoice_transaction_line_portal_type)))
self.assertEquals(3,len(new_invoice.objectValues(
portal_type=self.invoice_transaction_line_portal_type)))
account_module = self.getAccountModule()
account_module = self.portal.account_module
found_dict = {}
for line in invoice.objectValues(
portal_type=self.invoice_transaction_line_portal_type):
......@@ -761,7 +724,7 @@ class TestInvoiceMixin(TestPackingListMixin,
sequence_list=None, **kw):
"""Rebuilds with sale_invoice_builder and checks nothing more is
created. """
accounting_module = self.getAccountingModule()
accounting_module = self.portal.accounting_module
portal_type_list = ('Sale Invoice Transaction', 'Purchase Invoice Transaction')
sale_invoice_transaction_count = len(accounting_module.objectValues(
portal_type=portal_type_list))
......@@ -1195,8 +1158,6 @@ class TestInvoice(TestInvoiceMixin):
portal_type='Currency',
title='Currency',
base_unit_quantity=0.01)
self.createInvoiceTransactionRule(currency)
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
......@@ -1209,6 +1170,7 @@ class TestInvoice(TestInvoiceMixin):
default_address_region=self.default_region)
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1266,6 +1228,7 @@ class TestInvoice(TestInvoiceMixin):
price_currency= currency.getRelativeUrl())
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1457,8 +1420,6 @@ class TestInvoice(TestInvoiceMixin):
portal_type='Currency',
title='Currency',
base_unit_quantity=0.01)
self.createInvoiceTransactionRule(currency)
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
......@@ -1469,6 +1430,7 @@ class TestInvoice(TestInvoiceMixin):
default_address_region=self.default_region)
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1675,6 +1637,7 @@ class TestInvoice(TestInvoiceMixin):
portal_type=self.invoice_portal_type,
start_date=DateTime(2008, 12, 31),
title='Invoice',
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1714,6 +1677,7 @@ class TestInvoice(TestInvoiceMixin):
portal_type=self.invoice_portal_type,
start_date=DateTime(2008, 12, 31),
title='Invoice',
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1765,6 +1729,7 @@ class TestInvoice(TestInvoiceMixin):
portal_type=self.invoice_portal_type,
start_date=DateTime(2008, 12, 31),
title='Invoice',
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1804,6 +1769,7 @@ class TestInvoice(TestInvoiceMixin):
title='Vendor')
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1900,6 +1866,7 @@ class TestInvoice(TestInvoiceMixin):
no_order_packing_list = \
self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
portal_type=self.packing_list_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1992,6 +1959,7 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
title='Vendor')
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -2088,6 +2056,7 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
title='Vendor')
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -2173,7 +2142,6 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
......@@ -2186,6 +2154,7 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
default_address_region=self.default_region)
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -2250,6 +2219,7 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
default_address_region=self.default_region)
order = self.portal.getDefaultModule(self.order_portal_type).newContent(
portal_type=self.order_portal_type,
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -2470,7 +2440,6 @@ class TestSaleInvoiceMixin(TestInvoiceMixin,
PACKING_LIST_DEFAULT_SEQUENCE = """
stepCreateEntities
stepCreateCurrency
stepCreateSaleInvoiceTransactionRule
stepCreateOrder
stepSetOrderProfile
stepSetOrderPriceCurrency
......@@ -2498,7 +2467,6 @@ class TestSaleInvoiceMixin(TestInvoiceMixin,
PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE = """
stepCreateEntities
stepCreateCurrency
stepCreateSaleInvoiceTransactionRule
stepCreateOrder
stepSetOrderProfile
stepSetOrderPriceCurrency
......@@ -2532,7 +2500,6 @@ class TestSaleInvoiceMixin(TestInvoiceMixin,
TWO_PACKING_LIST_DEFAULT_SEQUENCE = """
stepCreateEntities
stepCreateCurrency
stepCreateSaleInvoiceTransactionRule
stepCreateOrder
stepSetOrderProfile
stepSetOrderPriceCurrency
......@@ -2602,6 +2569,7 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
stepRebuildAndCheckNothingIsCreated
stepCheckInvoicesConsistency
stepCheckInvoiceLineHasReferenceAndIntIndex
Pdb
""")
sequence_list.play(self, quiet=quiet)
......@@ -2665,6 +2633,7 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
stepEditInvoice
stepCheckInvoiceRuleNotAppliedOnInvoiceEdit
stepCheckInvoicesConsistency
stepTic
""")
sequence_list.play(self, quiet=quiet)
......@@ -2683,6 +2652,7 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
stepEditPackingList
stepCheckDeliveryRuleNotAppliedOnPackingListEdit
stepCheckInvoicesConsistency
stepTic
""")
sequence_list.play(self, quiet=quiet)
......@@ -2731,6 +2701,7 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
stepCheckInvoiceBuilding
stepRebuildAndCheckNothingIsCreated
stepCheckInvoicesConsistency
stepTic
""")
sequence_list.play(self, quiet=quiet)
......@@ -2804,10 +2775,12 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
"""
Change the start_date of a Invoice Line,
check that the invoice is divergent,
then accept decision, and check Packing list is divergent
then accept decision, and check Packing list is *not* divergent,
because Unify Solver does not propagage the change to the upper
simulation movement.
"""
if not quiet:
self.logMessage('Invoice Change Sart Date')
self.logMessage('Invoice Change Start Date')
sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
"""
stepSetReadyPackingList
......@@ -2830,7 +2803,12 @@ class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
stepCheckInvoiceIsNotDivergent
stepCheckInvoiceIsSolved
stepCheckPackingListIsDivergent
stepCheckPackingListIsNotDivergent
stepCheckPackingListIsSolved
stepCheckInvoiceTransactionRule
stepRebuildAndCheckNothingIsCreated
stepCheckInvoicesConsistency
"""
self.playSequence(sequence, quiet=quiet)
......@@ -3504,7 +3482,6 @@ class TestPurchaseInvoice(TestInvoice, ERP5TypeTestCase):
PACKING_LIST_DEFAULT_SEQUENCE = """
stepCreateEntities
stepCreateCurrency
stepCreateSaleInvoiceTransactionRule
stepCreateOrder
stepSetOrderProfile
stepSetOrderPriceCurrency
......
......@@ -51,6 +51,7 @@ class TestOrderMixin(SubcontentReindexingWrapper):
order_line_portal_type = 'Sale Order Line'
order_cell_portal_type = 'Sale Order Cell'
applied_rule_portal_type = 'Applied Rule'
simulation_movement_portal_type = 'Simulation Movement'
datetime = DateTime()
packing_list_portal_type = 'Sale Packing List'
packing_list_line_portal_type = 'Sale Packing List Line'
......
......@@ -1464,7 +1464,7 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
packing_list = self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
portal_type=self.packing_list_portal_type,
title='Packing List',
specialise='business_process_module/erp5_default_business_process',
specialise=self.business_process,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
......@@ -1538,7 +1538,7 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
portal_type=self.packing_list_portal_type,
source_value=source,
destination_value=destination,
specialise='business_process_module/erp5_default_business_process',
specialise=self.business_process,
start_date=DateTime())
packing_list_line = packing_list.newContent(
portal_type=self.packing_list_line_portal_type,
......@@ -1778,9 +1778,7 @@ class TestSolvingPackingList(TestPackingListMixin, ERP5TypeTestCase):
self.portal.portal_solvers.manage_delObjects(self.added_target_solver_list)
transaction.commit()
self.tic()
beforeTearDown = getattr(TestPackingListMixin, 'beforeTearDown',
ERP5TypeTestCase.beforeTearDown)
beforeTearDown(self)
super(TestSolvingPackingList, self).beforeTearDown()
@UnrestrictedMethod
def _setUpTargetSolver(self, solver_id, solver_class, tested_property_list):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment