Commit ca902a87 authored by Alexandre Boeglin's avatar Alexandre Boeglin

Added more tests for Invoice Transaction Rule generated movements.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7325 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 036ac378
...@@ -50,7 +50,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -50,7 +50,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \ from AccessControl.SecurityManagement import newSecurityManager, \
noSecurityManager noSecurityManager
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base, aq_inner from Acquisition import aq_base, aq_inner, aq_parent
from zLOG import LOG from zLOG import LOG
from Products.ERP5Type.DateUtils import addToDate from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
...@@ -74,6 +74,19 @@ class TestInvoice(TestPackingListMixin, ...@@ -74,6 +74,19 @@ class TestInvoice(TestPackingListMixin,
sale_gap = 'fr/pcg/7/70/707/7071/70712' sale_gap = 'fr/pcg/7/70/707/7071/70712'
customer_gap = 'fr/pcg/4/41/411' customer_gap = 'fr/pcg/4/41/411'
# (account_id, account_gap)
account_definition_list = (
('receivable_vat', vat_gap),
('sale', sale_gap),
('customer', customer_gap),
)
# (line_id, source_account_id, line_quantity)
transaction_line_definition_list = (
('income', 'sale', 1.0),
('receivable', 'customer', -1.0 - vat_rate),
('collected_vat', 'receivable_vat', vat_rate),
)
invoice_portal_type = 'Sale Invoice Transaction' invoice_portal_type = 'Sale Invoice Transaction'
invoice_line_portal_type = 'Invoice Line' invoice_line_portal_type = 'Invoice Line'
invoice_cell_portal_type = 'Invoice Cell' invoice_cell_portal_type = 'Invoice Cell'
...@@ -166,19 +179,12 @@ class TestInvoice(TestPackingListMixin, ...@@ -166,19 +179,12 @@ class TestInvoice(TestPackingListMixin,
portal = self.getPortal() portal = self.getPortal()
account_module = self.getAccountModule() account_module = self.getAccountModule()
for account_id, account_gap in (('receivable_vat', self.vat_gap), for account_id, account_gap in self.account_definition_list:
('sale', self.sale_gap),
('customer', self.customer_gap)):
if not account_id in account_module.objectIds(): if not account_id in account_module.objectIds():
account = account_module.newContent(id=account_id) account = account_module.newContent(id=account_id)
account.setGap(account_gap) account.setGap(account_gap)
portal.portal_workflow.doActionFor(account, portal.portal_workflow.doActionFor(account,
'validate_action', wf_id='account_workflow') 'validate_action', wf_id='account_workflow')
vat_account = account_module['receivable_vat']
sale_account = account_module['sale']
customer_account = account_module['customer']
invoice_rule = self.getPortal().portal_rules\ invoice_rule = self.getPortal().portal_rules\
.default_invoice_transaction_rule .default_invoice_transaction_rule
invoice_rule.deleteContent([x.getId() invoice_rule.deleteContent([x.getId()
...@@ -207,14 +213,12 @@ class TestInvoice(TestPackingListMixin, ...@@ -207,14 +213,12 @@ class TestInvoice(TestPackingListMixin,
self.assertEquals(len(cell_list),1) self.assertEquals(len(cell_list),1)
cell = cell_list[0] cell = cell_list[0]
for line_id, line_source, line_ratio in (('income', sale_account, 1.0), for line_id, line_source_id, line_ratio in \
('receivable', customer_account, -1.0 - self.vat_rate), self.transaction_line_definition_list:
('collected_vat', vat_account, self.vat_rate)):
line = cell.newContent(id=line_id, line = cell.newContent(id=line_id,
portal_type=self.sale_invoice_transaction_portal_type) portal_type=self.sale_invoice_transaction_portal_type)
line.setQuantity(line_ratio) line.setQuantity(line_ratio)
line.setSourceValue(line_source) line.setSourceValue(account_module[line_source_id])
def modifyPackingListState(self, transition_name, def modifyPackingListState(self, transition_name,
sequence,packing_list=None): sequence,packing_list=None):
...@@ -418,31 +422,61 @@ class TestInvoice(TestPackingListMixin, ...@@ -418,31 +422,61 @@ class TestInvoice(TestPackingListMixin,
""" Checks that the invoicing rule is applied and its values are """ Checks that the invoicing rule is applied and its values are
correct. """ correct. """
order_rule_list = sequence.get('order_rule_list') order_rule_list = sequence.get('order_rule_list')
invoicing_rule_list = []
invoice_transaction_rule_list = []
for order_rule in order_rule_list : for order_rule in order_rule_list :
for order_simulation_movement in order_rule.objectValues() : for order_simulation_movement in order_rule.objectValues() :
invoicing_rule_list = order_simulation_movement.objectValues() temp_invoicing_rule_list = order_simulation_movement.objectValues()
self.assertEquals(len(invoicing_rule_list), 1) self.assertEquals(len(temp_invoicing_rule_list), 1)
invoicing_rule = invoicing_rule_list[0] invoicing_rule_list.extend(order_simulation_movement.objectValues())
sequence.edit(invoicing_rule = invoicing_rule) sequence.edit(invoicing_rule_list=invoicing_rule_list)
self.assertEquals(invoicing_rule.getSpecialiseId(), invoicing_rule = invoicing_rule_list[0]
'default_invoicing_rule') sequence.edit(invoicing_rule = invoicing_rule)
self.assertEquals(invoicing_rule.getPortalType(), for invoicing_rule in invoicing_rule_list:
'Applied Rule') self.assertEquals(invoicing_rule.getSpecialiseId(),
'default_invoicing_rule')
simulation_movement_list = invoicing_rule.objectValues() self.assertEquals(invoicing_rule.getPortalType(),
self.assertNotEquals(len(simulation_movement_list), 0) 'Applied Rule')
for simulation_movement in simulation_movement_list : simulation_movement_list = invoicing_rule.objectValues()
resource_list = sequence.get('resource_list') self.assertNotEquals(len(simulation_movement_list), 0)
self.assertEquals(simulation_movement.getPortalType(), for simulation_movement in simulation_movement_list :
'Simulation Movement') invoice_transaction_rule_list.extend(simulation_movement.objectValues())
self.assertTrue(simulation_movement.getResourceValue() in resource_list = sequence.get('resource_list')
resource_list) self.assertEquals(simulation_movement.getPortalType(),
# TODO: What is the invoice dates supposed to be ? 'Simulation Movement')
# is this done through profiles ? self.assertTrue(simulation_movement.getResourceValue() in
self.assertEquals(simulation_movement.getStartDate(), resource_list)
sequence.get('order').getStartDate()) self.assertTrue(simulation_movement.isConvergent())
self.assertEquals(simulation_movement.getStopDate(), # TODO: What is the invoice dates supposed to be ?
sequence.get('order').getStopDate()) # is this done through profiles ?
self.assertEquals(simulation_movement.getStartDate(),
sequence.get('order').getStartDate())
self.assertEquals(simulation_movement.getStopDate(),
sequence.get('order').getStopDate())
sequence.edit(invoice_transaction_rule_list=invoice_transaction_rule_list)
def stepCheckInvoiceTransactionRule(self, sequence=None, sequence_list=None,
**kw):
"""
Checks that the invoice_transaction_rule is expanded and its movements are
consistent with its parent movement
"""
invoice_transaction_rule_list = \
sequence.get('invoice_transaction_rule_list')
for invoice_transaction_rule in invoice_transaction_rule_list:
parent_movement = aq_parent(invoice_transaction_rule)
self.assertEquals(3, len(invoice_transaction_rule.objectValues()))
for line_id, line_source_id, line_ratio in \
self.transaction_line_definition_list:
movement = getattr(invoice_transaction_rule, line_id, None)
self.assertTrue(movement is not None)
self.assertEquals(movement.getQuantity(), parent_movement.getPrice() *
parent_movement.getQuantity() * line_ratio)
self.assertEquals(movement.getSourceId(), line_source_id)
self.assertEquals(movement.getStartDate(),
parent_movement.getStartDate())
self.assertEquals(movement.getStopDate(),
parent_movement.getStopDate())
def stepCheckDeliveryRuleForDeferred( def stepCheckDeliveryRuleForDeferred(
self, sequence=None, sequence_list=None, **kw): self, sequence=None, sequence_list=None, **kw):
...@@ -545,9 +579,6 @@ class TestInvoice(TestPackingListMixin, ...@@ -545,9 +579,6 @@ class TestInvoice(TestPackingListMixin,
self.assertEquals(3,len(new_invoice.objectValues( self.assertEquals(3,len(new_invoice.objectValues(
portal_type=self.sale_invoice_transaction_line_portal_type))) portal_type=self.sale_invoice_transaction_line_portal_type)))
account_module = self.getAccountModule() account_module = self.getAccountModule()
vat_account=account_module['receivable_vat']
sale_account=account_module['sale']
customer_account=account_module['customer']
found_dict = {} found_dict = {}
for line in invoice.objectValues( for line in invoice.objectValues(
portal_type=self.sale_invoice_transaction_line_portal_type): portal_type=self.sale_invoice_transaction_line_portal_type):
...@@ -1024,6 +1055,7 @@ class TestInvoice(TestPackingListMixin, ...@@ -1024,6 +1055,7 @@ class TestInvoice(TestPackingListMixin,
stepTic stepTic
stepStartPackingList stepStartPackingList
stepCheckInvoicingRule stepCheckInvoicingRule
stepCheckInvoiceTransactionRule
stepTic stepTic
stepCheckInvoiceBuilding stepCheckInvoiceBuilding
...@@ -1035,6 +1067,7 @@ class TestInvoice(TestPackingListMixin, ...@@ -1035,6 +1067,7 @@ class TestInvoice(TestPackingListMixin,
stepCheckInvoiceSplitted stepCheckInvoiceSplitted
stepCheckPackingListIsDivergent stepCheckPackingListIsDivergent
stepCheckPackingListIsDiverged stepCheckPackingListIsDiverged
stepCheckInvoiceTransactionRule
stepRebuildAndCheckNothingIsCreated stepRebuildAndCheckNothingIsCreated
""" """
...@@ -1051,6 +1084,7 @@ class TestInvoice(TestPackingListMixin, ...@@ -1051,6 +1084,7 @@ class TestInvoice(TestPackingListMixin,
stepTic stepTic
stepStartPackingList stepStartPackingList
stepCheckInvoicingRule stepCheckInvoicingRule
stepCheckInvoiceTransactionRule
stepTic stepTic
stepCheckInvoiceBuilding stepCheckInvoiceBuilding
...@@ -1063,7 +1097,8 @@ class TestInvoice(TestPackingListMixin, ...@@ -1063,7 +1097,8 @@ class TestInvoice(TestPackingListMixin,
stepCheckPackingListIsDivergent stepCheckPackingListIsDivergent
stepCheckPackingListIsDiverged stepCheckPackingListIsDiverged
stepCheckSimulationStartDateUpdated stepCheckSimulationStartDateUpdated
stepCheckInvoiceTransactionRule
stepRebuildAndCheckNothingIsCreated stepRebuildAndCheckNothingIsCreated
""" """
self.playSequence(sequence) self.playSequence(sequence)
......
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