Commit 123a32d8 authored by Alexandre Boeglin's avatar Alexandre Boeglin

- Fixed existing tests in testInvoice.py

- Added helpers to testPackingList.py
- Removed wrong docstrings


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7277 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f492ee34
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
""" """
Tests invoice creation from simulation. Tests invoice creation from simulation.
...@@ -35,24 +34,35 @@ TODO: ...@@ -35,24 +34,35 @@ TODO:
* check divergence * check divergence
""" """
from random import randint
import os, sys import os, sys
if __name__ == '__main__': if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py')) execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder # Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log') os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300' os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager, \
noSecurityManager
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base, aq_inner
from zLOG import LOG from zLOG import LOG
from testPackingList import TestPackingListMixin from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName
from testPackingList import TestPackingListMixin
from testAccountingRules import TestAccountingRulesMixin from testAccountingRules import TestAccountingRulesMixin
class TestInvoice(TestAccountingRulesMixin, class TestInvoice(TestPackingListMixin,
TestPackingListMixin, TestAccountingRulesMixin,
ERP5TypeTestCase): ERP5TypeTestCase):
"""Test invoice are created from orders then packing lists. """ """Test invoice are created from orders then packing lists. """
...@@ -115,12 +125,16 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -115,12 +125,16 @@ class TestInvoice(TestAccountingRulesMixin,
def stepCreateEntities(self, sequence, **kw) : def stepCreateEntities(self, sequence, **kw) :
"""Create a vendor and a client. """ """Create a vendor and a client. """
self.stepCreateOrganisation1(sequence, **kw) self.stepCreateOrganisation1(sequence, **kw)
sequence.edit(client = sequence.get('organisation'))
self.stepCreateOrganisation2(sequence, **kw) self.stepCreateOrganisation2(sequence, **kw)
vendor = sequence.get('organisation') self.stepCreateOrganisation3(sequence, **kw)
vendor.setRegion(self.default_region) sequence.edit(vendor=sequence.get('organisation1'))
self.assertNotEquals(vendor.getRegionValue(), None) client1 = sequence.get('organisation2')
sequence.edit(vendor = vendor) client1.setRegion(self.default_region)
self.assertNotEquals(client1.getRegionValue(), None)
sequence.edit(client1=client1)
client2 = sequence.get('organisation3')
self.assertEquals(client2.getRegionValue(), None)
sequence.edit(client2=client2)
def stepCreateCurrency(self, sequence, **kw) : def stepCreateCurrency(self, sequence, **kw) :
"""Create a default currency. """ """Create a default currency. """
...@@ -148,23 +162,17 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -148,23 +162,17 @@ class TestInvoice(TestAccountingRulesMixin,
portal = self.getPortal() portal = self.getPortal()
account_module = self.getAccountModule() account_module = self.getAccountModule()
if not 'receivable_vat' in account_module.objectIds(): for account_id, account_gap in (('receivable_vat', self.vat_gap),
vat_account = account_module.newContent(id='receivable_vat') ('sale', self.sale_gap),
vat_account.setGap(self.vat_gap) ('customer', self.customer_gap)):
portal.portal_workflow.doActionFor(vat_account, if not account_id in account_module.objectIds():
'validate_action', wf_id='account_workflow') account = account_module.newContent(id=account_id)
account.setGap(account_gap)
portal.portal_workflow.doActionFor(account,
'validate_action', wf_id='account_workflow')
vat_account = account_module['receivable_vat'] vat_account = account_module['receivable_vat']
if not 'sale' in account_module.objectIds():
sale_account = account_module.newContent(id='sale')
sale_account.setGap(self.sale_gap)
portal.portal_workflow.doActionFor(sale_account,
'validate_action', wf_id='account_workflow')
sale_account = account_module['sale'] sale_account = account_module['sale']
if not 'customer' in account_module.objectIds():
customer_account = account_module.newContent(id='customer')
customer_account.setGap(self.customer_gap)
portal.portal_workflow.doActionFor(customer_account,
'validate_action', wf_id='account_workflow')
customer_account = account_module['customer'] customer_account = account_module['customer']
invoice_rule = self.getPortal().portal_rules\ invoice_rule = self.getPortal().portal_rules\
...@@ -194,19 +202,16 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -194,19 +202,16 @@ class TestInvoice(TestAccountingRulesMixin,
cell_list = invoice_rule.getCellValueList(base_id='movement') cell_list = invoice_rule.getCellValueList(base_id='movement')
self.assertEquals(len(cell_list),1) self.assertEquals(len(cell_list),1)
cell = cell_list[0] cell = cell_list[0]
income = cell.newContent(id='income',
portal_type=self.sale_invoice_transaction_portal_type) for line_id, line_source, line_ratio in (('income', sale_account, 1.0),
income.setQuantity(1.0) ('receivable', customer_account, -1.0 - self.vat_rate),
income.setSourceValue(sale_account) ('collected_vat', vat_account, self.vat_rate)):
receivable = cell.newContent(id='receivable',
portal_type=self.sale_invoice_transaction_portal_type) line = cell.newContent(id=line_id,
receivable.setQuantity(-1.196) portal_type=self.sale_invoice_transaction_portal_type)
receivable.setSourceValue(customer_account) line.setQuantity(line_ratio)
collected_vat = cell.newContent(id='collected_vat', line.setSourceValue(line_source)
portal_type=self.sale_invoice_transaction_portal_type)
collected_vat.setQuantity(self.vat_rate)
collected_vat.setSourceValue(vat_account)
def modifyPackingListState(self, transition_name, def modifyPackingListState(self, transition_name,
sequence,packing_list=None): sequence,packing_list=None):
""" calls the workflow for the packing list """ """ calls the workflow for the packing list """
...@@ -437,11 +442,11 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -437,11 +442,11 @@ class TestInvoice(TestAccountingRulesMixin,
simulation_movement_list = invoicing_rule.objectValues() simulation_movement_list = invoicing_rule.objectValues()
self.assertNotEquals(len(simulation_movement_list), 0) self.assertNotEquals(len(simulation_movement_list), 0)
for simulation_movement in simulation_movement_list : for simulation_movement in simulation_movement_list :
resource = sequence.get('resource') resource_list = sequence.get('resource_list')
self.assertEquals(simulation_movement.getPortalType(), self.assertEquals(simulation_movement.getPortalType(),
'Simulation Movement') 'Simulation Movement')
self.assertEquals(simulation_movement.getResourceValue(), self.assertTrue(simulation_movement.getResourceValue() in
resource) resource_list)
# TODO: What is the invoice dates supposed to be ? # TODO: What is the invoice dates supposed to be ?
# is this done through profiles ? # is this done through profiles ?
self.assertEquals(simulation_movement.getStartDate(), self.assertEquals(simulation_movement.getStartDate(),
...@@ -711,6 +716,40 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -711,6 +716,40 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckPackingListIsPacked stepCheckPackingListIsPacked
""" """
# default sequence for two lines of not varianted resource.
PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE = """
stepCreateSaleInvoiceTransactionRule
stepCreateEntities
stepCreateCurrency
stepCreateOrder
stepSetOrderProfile
stepSetOrderPriceCurrency
stepCreateNotVariatedResource
stepTic
stepCreateOrderLine
stepSetOrderLineResource
stepSetOrderLineDefaultValues
stepCreateNotVariatedResource
stepTic
stepCreateOrderLine
stepSetOrderLineResource
stepSetOrderLineDefaultValues
stepOrderOrder
stepTic
stepCheckDeliveryBuilding
stepConfirmOrder
stepTic
stepCheckOrderRule
stepCheckOrderSimulation
stepCheckDeliveryBuilding
stepAddPackingListContainer
stepAddPackingListContainerLine
stepTic
stepSetContainerFullQuantity
stepTic
stepCheckPackingListIsPacked
"""
# default sequence for one line of not varianted resource. # default sequence for one line of not varianted resource.
TWO_PACKING_LIST_DEFAULT_SEQUENCE = """ TWO_PACKING_LIST_DEFAULT_SEQUENCE = """
stepCreateSaleInvoiceTransactionRule stepCreateSaleInvoiceTransactionRule
...@@ -732,12 +771,12 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -732,12 +771,12 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckOrderRule stepCheckOrderRule
stepCheckOrderSimulation stepCheckOrderSimulation
stepCheckDeliveryBuilding stepCheckDeliveryBuilding
DecreasePackingListLineQuantity stepDecreasePackingListLineQuantity
CheckPackingListIsCalculating stepCheckPackingListIsCalculating
SplitAndDeferPackingList stepSplitAndDeferPackingList
Tic stepTic
CheckPackingListIsSolved stepCheckPackingListIsSolved
CheckPackingListSplitted stepCheckPackingListSplitted
stepAddPackingListContainer stepAddPackingListContainer
stepAddPackingListContainerLine stepAddPackingListContainerLine
stepSetContainerLineFullQuantity stepSetContainerLineFullQuantity
...@@ -748,8 +787,9 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -748,8 +787,9 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckNewPackingListIsPacked stepCheckNewPackingListIsPacked
""" """
def test_SimpleInvoice(self, quiet=0, run=RUN_ALL_TESTS): def test_01_SimpleInvoice(self, quiet=0, run=RUN_ALL_TESTS):
"""Checks that a Simple Invoice is created from a Packing List""" """Checks that a Simple Invoice is created from a Packing List"""
if not run: return
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
...@@ -763,7 +803,7 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -763,7 +803,7 @@ class TestInvoice(TestAccountingRulesMixin,
stepRebuildAndCheckNothingIsCreated stepRebuildAndCheckNothingIsCreated
""") """)
def test_TwoInvoicesFromTwoPackingList(self, quiet=0, run=1): def test_02_TwoInvoicesFromTwoPackingList(self, quiet=0, run=RUN_ALL_TESTS):
""" This test was created for the following bug: """ This test was created for the following bug:
- an order is created and confirmed - an order is created and confirmed
- the packing list is split - the packing list is split
...@@ -773,6 +813,7 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -773,6 +813,7 @@ class TestInvoice(TestAccountingRulesMixin,
so we have an invoice with twice the number of accounting rules so we have an invoice with twice the number of accounting rules
and an invoice with no accounting rules. both invoices are wrong and an invoice with no accounting rules. both invoices are wrong
""" """
if not run: return
for base_sequence in (TestInvoice.TWO_PACKING_LIST_DEFAULT_SEQUENCE, ) : for base_sequence in (TestInvoice.TWO_PACKING_LIST_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
...@@ -790,17 +831,18 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -790,17 +831,18 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckTwoInvoicesTransactionLines stepCheckTwoInvoicesTransactionLines
""") """)
def test_InvoiceEditAndInvoiceRule(self, quiet=0, run=1): def test_03_InvoiceEditAndInvoiceRule(self, quiet=0, run=RUN_ALL_TESTS):
"""Invoice Rule should not be applied on invoice lines created from\ """Invoice Rule should not be applied on invoice lines created from\
Packing List. Packing List.
We went to prevent this from happening: We want to prevent this from happening:
- Create a packing list - Create a packing list
- An invoice is created from packing list - An invoice is created from packing list
- Invoice is edited, updateAppliedRule is called - Invoice is edited, updateAppliedRule is called
- A new Invoice Rule is created for this invoice, and accounting - A new Invoice Rule is created for this invoice, and accounting
movements for this invoice are present twice in the simulation. movements for this invoice are present twice in the simulation.
""" """
if not run: return
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
...@@ -815,10 +857,11 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -815,10 +857,11 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckInvoiceRuleNotAppliedOnInvoiceEdit stepCheckInvoiceRuleNotAppliedOnInvoiceEdit
""") """)
def test_PackingListEditAndInvoiceRule(self, quiet=0, run=1): def test_04_PackingListEditAndInvoiceRule(self, quiet=0, run=RUN_ALL_TESTS):
"""Delivery Rule should not be applied on packing list lines created\ """Delivery Rule should not be applied on packing list lines created\
from Order. from Order.
""" """
if not run: return
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
...@@ -827,9 +870,10 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -827,9 +870,10 @@ class TestInvoice(TestAccountingRulesMixin,
stepCheckDeliveryRuleNotAppliedOnPackingListEdit stepCheckDeliveryRuleNotAppliedOnPackingListEdit
""") """)
def DISABLEDtest_InvoiceEditPackingListLine(self, quiet=0, run=RUN_ALL_TESTS): def test_05_InvoiceEditPackingListLine(self, quiet=0, run=RUN_ALL_TESTS):
"""Checks that editing a Packing List Line still creates a correct """Checks that editing a Packing List Line still creates a correct
Invoice""" Invoice"""
if not run: return
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
...@@ -844,12 +888,12 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -844,12 +888,12 @@ class TestInvoice(TestAccountingRulesMixin,
stepRebuildAndCheckNothingIsCreated stepRebuildAndCheckNothingIsCreated
""") """)
def DISABLEDtest_InvoiceDeletePackingListLine(self, quiet=0, def test_06_InvoiceDeletePackingListLine(self, quiet=0,
run=RUN_ALL_TESTS): run=RUN_ALL_TESTS):
"""Checks that deleting a Packing List Line still creates a correct """Checks that deleting a Packing List Line still creates a correct
Invoice""" Invoice"""
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : if not run: return
# XXX use another sequence that creates 2 lines for base_sequence in (TestInvoice.PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE, ) :
self.playSequence( self.playSequence(
base_sequence + base_sequence +
""" """
...@@ -863,15 +907,19 @@ class TestInvoice(TestAccountingRulesMixin, ...@@ -863,15 +907,19 @@ class TestInvoice(TestAccountingRulesMixin,
stepRebuildAndCheckNothingIsCreated stepRebuildAndCheckNothingIsCreated
""") """)
def DISABLEDtest_InvoiceAddPackingListLine(self, quiet=0, run=RUN_ALL_TESTS): def test_07_InvoiceAddPackingListLine(self, quiet=0, run=RUN_ALL_TESTS):
"""Checks that adding a Packing List Line still creates a correct """Checks that adding a Packing List Line still creates a correct
Invoice""" Invoice"""
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE, ) : if not run: return
for base_sequence in (TestInvoice.PACKING_LIST_DEFAULT_SEQUENCE,
TestInvoice.PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE) :
# XXX use another sequence that creates 2 lines # XXX use another sequence that creates 2 lines
self.playSequence( self.playSequence(
base_sequence + base_sequence +
""" """
stepAddPackingListLine stepAddPackingListLine
stepSetContainerFullQuantity
stepTic
stepSetReadyPackingList stepSetReadyPackingList
stepTic stepTic
stepStartPackingList stepStartPackingList
......
...@@ -82,13 +82,13 @@ class TestOrderMixin: ...@@ -82,13 +82,13 @@ class TestOrderMixin:
""" """
return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_apparel',) return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_apparel',)
def login(self, quiet=0, run=run_all_test): def login(self, quiet=0, run=1):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('rc', '', ['Manager', 'Member'], []) uf._doAddUser('rc', '', ['Manager', 'Member'], [])
user = uf.getUserById('rc').__of__(uf) user = uf.getUserById('rc').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def afterSetUp(self, quiet=1, run=run_all_test): def afterSetUp(self, quiet=1, run=1):
self.login() self.login()
portal = self.getPortal() portal = self.getPortal()
self.category_tool = self.getCategoryTool() self.category_tool = self.getCategoryTool()
......
...@@ -312,7 +312,7 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -312,7 +312,7 @@ class TestPackingListMixin(TestOrderMixin):
def stepCheckSimulationDestinationUpdated(self,sequence=None, sequence_list=None, **kw): def stepCheckSimulationDestinationUpdated(self,sequence=None, sequence_list=None, **kw):
""" """
Create a empty organisation XXX
""" """
applied_rule = sequence.get('applied_rule') applied_rule = sequence.get('applied_rule')
simulation_line_list = applied_rule.objectValues() simulation_line_list = applied_rule.objectValues()
...@@ -323,14 +323,14 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -323,14 +323,14 @@ class TestPackingListMixin(TestOrderMixin):
def stepChangePackingListStartDate(self, sequence=None, sequence_list=None, **kw): def stepChangePackingListStartDate(self, sequence=None, sequence_list=None, **kw):
""" """
Test if packing list is divergent XXX
""" """
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list.edit(start_date=self.datetime + 15) packing_list.edit(start_date=self.datetime + 15)
def stepCheckSimulationStartDateUpdated(self,sequence=None, sequence_list=None, **kw): def stepCheckSimulationStartDateUpdated(self,sequence=None, sequence_list=None, **kw):
""" """
Create a empty organisation XXX
""" """
applied_rule = sequence.get('applied_rule') applied_rule = sequence.get('applied_rule')
simulation_line_list = applied_rule.objectValues() simulation_line_list = applied_rule.objectValues()
...@@ -338,14 +338,34 @@ class TestPackingListMixin(TestOrderMixin): ...@@ -338,14 +338,34 @@ class TestPackingListMixin(TestOrderMixin):
for simulation_line in simulation_line_list: for simulation_line in simulation_line_list:
self.assertEquals(simulation_line.getStartDate(),self.datetime + 15) self.assertEquals(simulation_line.getStartDate(),self.datetime + 15)
def stepEditPackingListLine(self,sequence=None, sequence_list=None, **kw):
"""
Edits a Packing List Line
"""
packing_list_line = sequence.get('packing_list_line')
packing_list_line.edit(description='This line was edited!')
def stepDeletePackingListLine(self,sequence=None, sequence_list=None, **kw): def stepDeletePackingListLine(self,sequence=None, sequence_list=None, **kw):
""" """
Create a empty organisation Deletes a Packing List Line
""" """
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list_line_id = sequence.get('packing_list_line').getId() packing_list_line_id = sequence.get('packing_list_line').getId()
packing_list.manage_delObjects([packing_list_line_id]) packing_list.manage_delObjects([packing_list_line_id])
def stepAddPackingListLine(self,sequence=None, sequence_list=None, **kw):
"""
Adds a Packing List Line
"""
packing_list = sequence.get('packing_list')
packing_list_line = packing_list.newContent(
portal_type=self.packing_list_line_portal_type)
self.stepCreateNotVariatedResource(sequence=sequence,
sequence_list=sequence_list, **kw)
resource = sequence.get('resource')
packing_list_line.setResourceValue(resource)
packing_list_line.edit(price=100, quantity=200)
def stepCheckSimulationConnected(self,sequence=None, sequence_list=None, **kw): def stepCheckSimulationConnected(self,sequence=None, sequence_list=None, **kw):
""" """
Check if simulation movement are disconnected Check if simulation movement are disconnected
......
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