From f97525dea1bae76b4bd59e14cc8407c616c73525 Mon Sep 17 00:00:00 2001 From: Alexandre Boeglin <alex@nexedi.com> Date: Fri, 14 Jan 2005 13:40:28 +0000 Subject: [PATCH] Extended test to include Invoice and Payment Transactions. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2210 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/tests/testInvoice.py | 213 +++++++++++++++++++++++++++--- 1 file changed, 192 insertions(+), 21 deletions(-) diff --git a/product/ERP5/tests/testInvoice.py b/product/ERP5/tests/testInvoice.py index c2ca2adb27..088abd805e 100755 --- a/product/ERP5/tests/testInvoice.py +++ b/product/ERP5/tests/testInvoice.py @@ -88,6 +88,18 @@ class Test(ERP5TypeTestCase): """ return ('erp5_trade','erp5_accounting','erp5_pdm') + def enableLightInstall(self): + """ + You can override this. Return if we should do a light install (1) or not (0) + """ + return 1 + + def enableActivityTool(self): + """ + You can override this. Return if we should create (1) or not (0) an activity tool + """ + return 1 + def getSaleOrderModule(self): return getattr(self.getPortal(),'sale_order',None) @@ -112,20 +124,62 @@ class Test(ERP5TypeTestCase): def afterSetUp(self, quiet=1, run=1): """ """ + # Create categories + self.category_tool = self.getCategoryTool() + o = self.category_tool.region.newContent(portal_type='Category', id='europe') + o = o.newContent(portal_type='Category', id='west') + o.newContent(portal_type='Category', id='france') + + self.category_tool.pcg.newContent(portal_type='Category', id='1') + + o = self.category_tool.product_line.newContent(portal_type='Category', id='storever') + o.newContent(portal_type='Category', id='notebook') # Create a product product_module = self.getProductModule() - product = product_module.newContent(portal_type='Product',id='1') + product = product_module.newContent(portal_type='Product',id='1', product_line='storever/notebook') product.setPricedQuantity(1.0) product.setBasePrice(self.price1) - # Create a destination + # Create a destination with region organisation_module = self.getOrganisationModule() organisation = organisation_module.newContent(portal_type='Organisation',id=self.destination_company_id) + organisation.newContent(id='default_address', portal_type='Address', region='europe/west/france') organisation = organisation_module.newContent(portal_type='Organisation',id=self.source_company_id) # Create some accounts account_module = self.getAccountModule() account_module.newContent(portal_type='Account',id='prestation_service') account_module.newContent(portal_type='Account',id='creance_client') account_module.newContent(portal_type='Account',id='tva_collectee_196') + account_module.newContent(portal_type='Account',id='dette_fournisseur') + account_module.newContent(portal_type='Account',id='banques_etablissements_financiers') + account_module.newContent(portal_type='Account',id='account1') + account_module.newContent(portal_type='Account',id='account2') + account_module.newContent(portal_type='Account',id='account3') + account_module.newContent(portal_type='Account',id='account4') + # Create some predicates + self.invoice_transaction_rule = self.getPortal().portal_rules.default_invoice_transaction_rule + self.invoice_transaction_rule.deleteContent(self.invoice_transaction_rule.contentIds()) # delete anything inside the rule first + + self.predicate_product1 = self.invoice_transaction_rule.newContent(id='product_1', title='product_1', portal_type='Predicate Group', string_index='product', int_index='1', membership_criterion_base_category_list=['product_line',], membership_criterion_category_list=['product_line/storever/notebook'], immediate_reindex=1) + self.predicate_region1 = self.invoice_transaction_rule.newContent(id='region_1', title='region_1', portal_type='Predicate Group', string_index='region', int_index='1', membership_criterion_base_category_list=['region',], membership_criterion_category_list=['region/europe/west/france'], immediate_reindex=1) + #self.invoice_transaction_rule.recursiveImmediateReindexObject() + # Update the matrix + self.invoice_transaction_rule.updateMatrix() + # add some values to the transaction lines in the accounting rule cell + cell_list = self.invoice_transaction_rule.contentValues(filter={'portal_type':'Accounting Rule Cell'}) + self.assertEqual(len(cell_list), 1) # Check that the rule is here + self.product1_region1_cell = getattr(self.invoice_transaction_rule, 'vat_per_region_0_0', None) + self.failUnless(self.product1_region1_cell != None) + + self.product1_region1_line1 = getattr(self.product1_region1_cell, 'income', None) + self.failUnless(self.product1_region1_line1 != None) + self.product1_region1_line1.edit(title='income', source='account/prestation_service', destination='account/account1', quantity=1) + + self.product1_region1_line2 = getattr(self.product1_region1_cell, 'receivable', None) + self.failUnless(self.product1_region1_line2 != None) + self.product1_region1_line2.edit(title='receivable', source='account/prestation_service', destination='account/account2', quantity=0.5) + # flush activities + #get_transaction().commit() + #self.tic() def stepTic(self, **kw): self.tic() @@ -155,16 +209,15 @@ class Test(ERP5TypeTestCase): order = order_module.newContent(portal_type='Sale Order') order.setStartDate(DateTime('2004-11-20')) order.setStopDate(DateTime('2004-11-24')) - destination_organisation = self.getOrganisationModule().getObject(self.destination_company_id) + destination_organisation = self.getOrganisationModule()[self.destination_company_id] order.setDestinationValue(destination_organisation) - source_organisation = self.getOrganisationModule().getObject(self.source_company_id) + source_organisation = self.getOrganisationModule()[self.source_company_id] order.setSourceValue(source_organisation) line1 = order.newContent(portal_type='Sale Order Line',id='1') product = sequence.get('product') line1.setResourceValue(product) line1.setTargetQuantity(self.quantity1) line1.setPrice(self.price1) - sequence.edit(product=product) sequence.edit(order=order) self.assertEquals(line1.getTotalPrice(),self.total_price1) @@ -196,7 +249,6 @@ class Test(ERP5TypeTestCase): rule_line = rule_line_list[0] sequence.edit(order_rule_line=rule_line) order_line = order_line_list[0] - product = sequence.get('product') self.assertEquals(rule_line.getTargetQuantity(),self.quantity1) self.assertEquals(rule_line.getPrice(),self.price1) self.assertEquals(rule_line.getOrderValue(),order_line) @@ -210,11 +262,18 @@ class Test(ERP5TypeTestCase): invoicing_rule_list = order_rule_line.objectValues() self.assertEquals(len(invoicing_rule_list),1) invoicing_rule = invoicing_rule_list[0] + sequence.edit(invoicing_rule=invoicing_rule) self.assertEquals(invoicing_rule.getSpecialiseId(),'default_invoicing_rule') self.assertEquals(invoicing_rule.getPortalType(),'Applied Rule') rule_line_list = invoicing_rule.objectValues() self.assertEquals(len(rule_line_list),1) rule_line = rule_line_list[0] + sequence.edit(invoicing_rule_line=rule_line) + product = sequence.get('product') + self.assertEquals(rule_line.getTargetQuantity(),self.quantity1) + self.assertEquals(rule_line.getPrice(),self.price1) + self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + self.assertEquals(rule_line.getResourceValue(), product) def stepCheckDeliveryRule(self,sequence=None, sequence_list=None,**kw): @@ -239,6 +298,55 @@ class Test(ERP5TypeTestCase): self.assertEquals(rule_line.getStopDate(),packing_list_line.getStopDate()) self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + def stepCheckInvoiceTransactionRule(self, sequence=None, sequence_list=None, **kw) : + invoicing_rule_line = sequence.get('invoicing_rule_line') + invoice_transaction_rule_list = invoicing_rule_line.objectValues() + self.assertEquals(len(invoice_transaction_rule_list),1) + invoice_transaction_rule = invoice_transaction_rule_list[0] + sequence.edit(invoice_transaction_rule=invoice_transaction_rule) + self.assertEquals(invoice_transaction_rule.getSpecialiseId(),'default_invoice_transaction_rule') + self.assertEquals(invoice_transaction_rule.getPortalType(),'Applied Rule') + rule_line_list = invoice_transaction_rule.objectValues() + self.assertEquals(len(rule_line_list),3) + for rule_line in rule_line_list : + if rule_line.getId() == 'income' : + self.assertEquals(rule_line.getSourceValue(), self.getAccountModule()['prestation_service']) + self.assertEquals(rule_line.getDestinationValue(), self.getAccountModule()['account1']) + self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + self.assertEquals(rule_line.getQuantity(), 3 * 72 * 1) + elif rule_line.getId() == 'receivable' : + self.assertEquals(rule_line.getSourceValue(), self.getAccountModule()['prestation_service']) + self.assertEquals(rule_line.getDestinationValue(), self.getAccountModule()['account2']) + self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + self.assertEquals(rule_line.getQuantity(), 3 * 72 * 0.5) + sequence.edit(invoice_transaction_rule_line_revceivable=rule_line) + elif rule_line.getId() == 'collected_vat' : + self.assertEquals(rule_line.getSourceValue(), self.getAccountModule()['tva_collectee_196']) # this is defined in SaleInvoiceTransaction_init in ERP5 skins. + else : + raise self.failureException, 'Unknown movement : %s' % repr(rule_line) + + def stepCheckPaymentRule(self, sequence=None, sequence_list=None, **kw) : + invoice_transaction_rule_line_revceivable = sequence.get('invoice_transaction_rule_line_revceivable') + payment_rule_list = invoice_transaction_rule_line_revceivable.objectValues() + self.assertEquals(len(payment_rule_list),1) + payment_rule = payment_rule_list[0] + sequence.edit(payment_rule=payment_rule) + self.assertEquals(payment_rule.getSpecialiseId(),'default_payment_rule') + self.assertEquals(payment_rule.getPortalType(),'Applied Rule') + rule_line_list = payment_rule.objectValues() + self.assertEquals(len(rule_line_list),2) + for rule_line in rule_line_list : + if rule_line.getId() == 'receivable' : + self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + self.assertEquals(rule_line.getQuantity(), 0 - invoice_transaction_rule_line_revceivable.getQuantity()) + sequence.edit(payment_rule_line_receivable=rule_line) + elif rule_line.getId() == 'bank' : + self.assertEquals(rule_line.getPortalType(),'Simulation Movement') + self.assertEquals(rule_line.getQuantity(), invoice_transaction_rule_line_revceivable.getQuantity()) + sequence.edit(payment_rule_line_bank=rule_line) + else : + raise self.failureException, 'Unknown movement : %s' % repr(rule_line) + def stepBuildDeliveryList(self,sequence=None, sequence_list=None,**kw): """ """ @@ -255,6 +363,18 @@ class Test(ERP5TypeTestCase): # It should be in a script inside the workflow packing_list.buildInvoiceList() + def stepBuildInvoiceTransactionList(self, sequence=None, sequence_list=None, **kw) : + invoice = sequence.get('invoice') + + # It should be in a script inside the workflow + invoice.buildInvoiceTransactionList() + + def stepBuildPaymentTransactionList(self, sequence=None, sequence_list=None, **kw) : + invoice = sequence.get('invoice') + + # It should be in a script inside the workflow + invoice.buildPaymentTransactionList() + def stepCheckPackingList(self,sequence=None, sequence_list=None,**kw): """ """ @@ -283,26 +403,76 @@ class Test(ERP5TypeTestCase): """ """ accounting_module = self.getAccountingModule() - delivery_rule = sequence.get('delivery_rule') - sale_invoice_transaction_list = [] - for o in accounting_module.objectValues(): - if delivery_rule.getDeliveryValue() == o: - sale_invoice_transaction_list.append(o) + #invoicing_rule = sequence.get('invoicing_rule') + sale_invoice_transaction_list = accounting_module.objectValues() + #for o in accounting_module.objectValues(): + #if invoicing_rule.getDeliveryValue() == o: + #sale_invoice_transaction_list.append(o) self.assertEquals(len(sale_invoice_transaction_list),1) sale_invoice = sale_invoice_transaction_list[0] - sale_invoice_line_list = sale_invoice.objectValues() + sequence.edit(invoice=sale_invoice) + sale_invoice_line_list = sale_invoice.contentValues(filter={'portal_type':'Invoice Line'}) + LOG('IL', 0, repr([[i, i.getQuantity(), i.getPrice()] for i in sale_invoice_line_list])) self.assertEquals(len(sale_invoice_line_list),1) sale_invoice_line = sale_invoice_line_list[0] + sequence.edit(invoice_line=sale_invoice_line) + product = sequence.get('product') self.assertEquals(sale_invoice_line.getResourceValue(),product) self.assertEquals(sale_invoice_line.getPrice(),self.price1) self.assertEquals(sale_invoice_line.getQuantity(),self.quantity1) self.assertEquals(sale_invoice_line.getTotalPrice(),self.total_price1) + LOG('ILR', 0, sale_invoice_line.getDeliveryRelatedValueList()) - - - - + def stepCheckInvoiceTransaction(self,sequence=None, sequence_list=None,**kw): + """ + """ + accounting_module = self.getAccountingModule() + sale_invoice_transaction_list = accounting_module.objectValues() + self.assertEquals(len(sale_invoice_transaction_list),1) + sale_invoice = sale_invoice_transaction_list[0] + sale_invoice_line_list = sale_invoice.contentValues(filter={'portal_type':'Sale Invoice Transaction Line'}) + LOG('SITL', 0, repr([[i, i.getQuantity(), i.getPrice()] for i in sale_invoice_line_list])) + self.assertEquals(len(sale_invoice_line_list),3) + + for transaction_line in sale_invoice_line_list : + if transaction_line.getId() == 'income' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['prestation_service']) + self.assertEquals(transaction_line.getDestinationValue(), self.getAccountModule()['account1']) + self.assertEquals(transaction_line.getQuantity(), 3 * 72 * 1) + elif transaction_line.getId() == 'receivable' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['prestation_service']) + self.assertEquals(transaction_line.getDestinationValue(), self.getAccountModule()['account2']) + self.assertEquals(transaction_line.getQuantity(), 3 * 72 * 0.5) + sequence.edit(invoice_transaction_line_receivable=transaction_line) + elif transaction_line.getId() == 'collected_vat' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['tva_collectee_196']) # this is defined in SaleInvoiceTransaction_init in ERP5 skins. + else : + raise self.failureException + + def stepCheckPaymentTransaction(self, sequence=None, sequence_list=None, **kw) : + """ + """ + accounting_module = self.getAccountingModule() + payment_transaction_list = accounting_module.contentValues(filter={'portal_type':'Payment Transaction'}) + self.assertEquals(len(payment_transaction_list),1) + payment_transaction = payment_transaction_list[0] + payment_transaction_line_list = payment_transaction.objectValues() + LOG('ATL', 0, repr([[i, i.getQuantity()] for i in payment_transaction_line_list])) + self.assertEquals(len(payment_transaction_line_list),3) + + invoice_transaction_line_receivable = sequence.get('invoice_transaction_line_receivable') + for transaction_line in payment_transaction_line_list : + if transaction_line.getId() == 'receivable' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['creance_client']) + self.assertEquals(transaction_line.getQuantity(), 0 - invoice_transaction_line_receivable.getQuantity()) + elif transaction_line.getId() == 'bank' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['banques_etablissements_financiers']) + self.assertEquals(transaction_line.getQuantity(), invoice_transaction_line_receivable.getQuantity()) + elif transaction_line.getId() == 'payable' : + self.assertEquals(transaction_line.getSourceValue(), self.getAccountModule()['dette_fournisseur']) # this is defined in SaleInvoiceTransaction_init in ERP5 skins. + else : + raise self.failureException def testInvoice(self, quiet=0,run=1): @@ -312,11 +482,12 @@ class Test(ERP5TypeTestCase): sequence_list = SequenceList() # Simple sequence # ... Fails - sequence_string = 'FirstCheck CreateSaleOrder CreateOrderRule Tic Tic' \ - + ' CheckOrderRule BuildDeliveryList CheckPackingList' \ - + ' Tic CheckInvoicingRule' \ - + ' BuildInvoiceList Tic Tic ' - #+ 'CheckInvoice' + sequence_string = 'FirstCheck CreateSaleOrder CreateOrderRule Tic' \ + + ' CheckOrderRule BuildDeliveryList Tic' \ + + ' CheckPackingList CheckInvoicingRule BuildInvoiceList Tic' \ + + ' CheckInvoice CheckInvoiceTransactionRule BuildInvoiceTransactionList Tic ' \ + + ' CheckInvoiceTransaction CheckPaymentRule BuildPaymentTransactionList Tic' \ + + ' CheckPaymentTransaction' sequence_list.addSequenceString(sequence_string) sequence_list.play(self) -- 2.30.9