Commit 64ae698e authored by Julien Muchembled's avatar Julien Muchembled

Finish rewrite of Invoice Transaction Simulation Rule for new simulation

We drop support of custom script (generate_prevision_script_id).

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37593 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ba8e40ff
......@@ -75,6 +75,10 @@
<key> <string>portal_type</string> </key>
<value> <string>Invoice Transaction Simulation Rule</string> </value>
</item>
<item>
<key> <string>same_total_quantity</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>test_method_id</string> </key>
<value>
......
......@@ -89,5 +89,8 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
class InvoicingRuleMovementGenerator(MovementGeneratorMixin):
def _getUpdatePropertyDict(self, input_movement):
return {'delivery': None}
def _getInputMovementList(self, movement_list=None, rounding=None):
return [self._applied_rule.getParentValue(),]
......@@ -111,9 +111,10 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
resource = invoice.getProperty('resource',
invoice.getProperty('price_currency', None))
if resource is None:
portal = input_movement.getPortalObject()
# search the resource on parents simulation movement's deliveries
simulation_movement = input_movement
portal_simulation = input_movement.getPortalObject().portal_simulation
portal_simulation = portal.portal_simulation
while resource is None and \
simulation_movement != portal_simulation :
delivery = simulation_movement.getDeliveryValue()
......@@ -129,7 +130,28 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
resource = order.getProperty('price_currency', None)
simulation_movement = simulation_movement\
.getParentValue().getParentValue()
return {'delivery': None, 'resource': resource, 'price': 1}
kw = {'delivery': None, 'resource': resource, 'price': 1}
if resource is not None:
#set asset_price on movement when resource is different from price
#currency of the source/destination section
for arrow in 'destination', 'source':
section = input_movement.getDefaultAcquiredValue(arrow + '_section')
if section is not None:
currency_url = section.getPriceCurrency()
if currency_url not in (None, resource):
currency = portal.unrestrictedTraverse(currency_url)
exchange_ratio = currency.getPrice(
context=input_movement.asContext(
categories=('price_currency/' + currency_url,
'resource/' + resource)))
if exchange_ratio is not None:
kw[arrow + '_total_asset_price'] = round(
exchange_ratio * input_movement.getQuantity(),
currency.getQuantityPrecision())
return kw
def _getInputMovementList(self, movement_list=None, rounding=False):
simulation_movement = self._applied_rule.getParentValue()
......@@ -140,103 +162,3 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
input_movement._setCategoryMembership('trade_phase',
('default/accounting',))
return (input_movement,)
# TODO: add support for assert prices (see old code below)
def __getGeneratedMovementList(self, movement_list=None, rounding=False):
"""
Input movement list comes from order
XXX This implementation is very primitive, and does not support BPM,
i.e. business paths are not taken into account.
"""
ret = []
rule = self._rule
# input_movement, business_path = rule._getInputMovementAndPathTupleList(
# applied_rule)[0]
input_movement = self._applied_rule.getParentValue()
parent_movement = self._applied_rule.getParentValue()
# Find a matching cell
cell = rule._getMatchingCell(input_movement)
if cell is not None:
for accounting_rule_cell_line in cell.objectValues():
if resource is None :
# last resort : get the resource from the rule
resource = accounting_rule_cell_line.getResource() \
or cell.getResource()
# XXX we need business path here?
kw = self._getPropertyAndCategoryList(input_movement, None, rule)
kw.update(
delivery=None,
source=[accounting_rule_cell_line.getSource()],
destination=[accounting_rule_cell_line.getDestination()],
quantity=(input_movement.getCorrectedQuantity() *
input_movement.getPrice(0.0)) *
accounting_rule_cell_line.getQuantity(),
resource=[resource],
price=1,
)
if resource is not None:
#set asset_price on movement when resource is different from price
#currency of the source/destination section
destination_exchange_ratio, precision = self \
._getCurrencyRatioAndPrecisionByArrow(
rule, 'destination_section', kw)
if destination_exchange_ratio is not None:
kw.update(destination_total_asset_price=round(
(destination_exchange_ratio*
parent_movement.getTotalPrice()),precision))
source_exchange_ratio, precision = self \
._getCurrencyRatioAndPrecisionByArrow(
rule, 'source_section', kw)
if source_exchange_ratio is not None:
kw.update(source_total_asset_price=round(
(source_exchange_ratio*
parent_movement.getTotalPrice()),precision))
if accounting_rule_cell_line.hasProperty(
'generate_prevision_script_id'):
generate_prevision_script_id = \
accounting_rule_cell_line.getGeneratePrevisionScriptId()
kw.update(getattr(input_movement,
generate_prevision_script_id)(kw))
simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getCurrencyRatioAndPrecisionByArrow(self, rule, arrow, prevision_line):
from Products.ERP5Type.Document import newTempSimulationMovement
try:
prevision_currency = prevision_line['resource'][0]
except IndexError:
prevision_currency = None
exchange_ratio = None
precision = None
try:
section = prevision_line.get(arrow, [])[0]
except IndexError:
section = None
if section is not None:
currency_url = rule.restrictedTraverse(section).getProperty(
'price_currency', None)
else:
currency_url = None
if currency_url is not None and prevision_currency != currency_url:
precision = section.getPriceCurrencyValue() \
.getQuantityPrecision()
temporary_movement = newTempSimulationMovement(rule.getPortalObject(),
'1', **prevision_line)
exchange_ratio = rule.restrictedTraverse(currency_url).getPrice(
context=temporary_movement.asContext(
categories=['price_currency/%s' % currency_url,
'resource/%s' % prevision_currency],
start_date=temporary_movement.getStartDate()))
return exchange_ratio, precision
......@@ -80,36 +80,28 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
('collected_vat', 'receivable_vat', 'refundable_vat', vat_rate),
)
@UnrestrictedMethod
def createCategoriesInCategory(self, category, category_id_list):
for category_id in category_id_list:
child = category
for id in category_id.split('/'):
try:
child = child[id]
except KeyError:
child = child.newContent(id)
def createCategories(self):
"""Create the categories for our test. """
for cat_string in self.getNeededCategoryList() :
base_cat = cat_string.split("/")[0]
path = self.getPortal().portal_categories[base_cat]
for cat in cat_string.split("/")[1:] :
if not cat in path.objectIds() :
path = path.newContent(
portal_type='Category',
id=cat,)
else:
path = path[cat]
# check categories have been created
for cat_string in self.getNeededCategoryList() :
self.assertNotEquals(None,
self.getCategoryTool().restrictedTraverse(cat_string),
cat_string)
def getNeededCategoryList(self):
"""return a list of categories that should be created."""
return ('region/%s' % self.default_region,
'gap/%s' % self.vat_gap,
'gap/%s' % self.sale_gap,
'gap/%s' % self.customer_gap,
'delivery_mode/%s' % self.mail_delivery_mode,
'incoterm/%s' % self.cpt_incoterm,
'quantity_unit/%s' % self.unit_piece_quantity_unit,
'quantity_unit/%s' % self.mass_quantity_unit,
)
category_tool = self.getCategoryTool()
_ = self.createCategoriesInCategory
_(category_tool.region, [self.default_region])
_(category_tool.gap, [self.vat_gap, self.sale_gap, self.customer_gap])
_(category_tool.delivery_mode, [self.mail_delivery_mode])
_(category_tool.incoterm, [self.cpt_incoterm])
_(category_tool.quantity_unit,
[self.unit_piece_quantity_unit, self.mass_quantity_unit])
_(category_tool.trade_phase, ['default'])
_(category_tool.trade_phase.default,
['accounting', 'delivery', 'invoicing', 'discount', 'tax', 'payment'])
def _solveDivergence(self, obj, property, decision, group='line'):
"""
......@@ -127,9 +119,19 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
'solve_divergence_action',
**kw)
def validateRules(self):
"""Enable all rules except temporarily broken payment rule"""
rule_tool = self.getRuleTool()
for rule in rule_tool.contentValues(
portal_type=rule_tool.getPortalRuleTypeList()):
if rule.getId() != 'new_payment_simulation_rule' and \
rule.getValidationState() != 'validated':
rule.validate()
def afterSetUp(self):
ERP5TypeTestCase.login(self)
self.createCategories()
self.validateRules()
self.createAndValidateAccounts()
self.login()
def beforeTearDown(self):
......@@ -168,65 +170,47 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
'erp5_accounting',
'erp5_accounting_ui_test',
'erp5_invoicing',
'erp5_simplified_invoicing'
'erp5_simplified_invoicing',
'erp5_simulation',
'erp5_simulation_test',
)
@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
def createAndValidateAccounts(self):
account_module = self.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]
account = account_module.newContent(account_id,
gap=account_gap, account_type=account_type)
self.portal.portal_workflow.doActionFor(account, 'validate_action')
def createBusinessProcess(self, resource=None):
self.business_process = business_process = \
self.portal.business_process_module.newContent()
trade_phase = self.getCategoryTool().trade_phase
kw = dict(portal_type='Trade Model Path',
trade_date='trade_phase/default/order')
business_process.newContent(
reference='default_path',
trade_phase_value_list=[x for x in trade_phase.default.objectValues()
if x.getId() != 'accounting'],
**kw)
kw.update(trade_phase='default/accounting',
resource_value=resource,
membership_criterion_base_category_list=(
'destination_region',
'product_line'),
membership_criterion_category_list=(
'destination_region/region/' + self.default_region,
'product_line/apparel'))
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()
business_process.newContent(
reference='acounting_' + line_id,
efficiency=line_ratio,
source='account_module/' + line_source_id,
destination='account_module/' + line_destination_id,
**kw)
transaction.commit()
self.tic()
......@@ -263,7 +247,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transactio
client = self.portal.organisation_module.newContent(
......@@ -283,6 +267,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
......@@ -356,7 +341,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transactio
client = self.portal.organisation_module.newContent(
......@@ -376,6 +361,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
......@@ -442,7 +428,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
......@@ -462,6 +448,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
......@@ -534,7 +521,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
......@@ -554,6 +541,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
......@@ -636,7 +624,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
......@@ -656,6 +644,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Purchase Order Line',
resource_value=resource,
......@@ -738,7 +727,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
self.createBusinessProcess(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
......@@ -760,6 +749,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
price_currency_value=currency,
delivery_mode=self.mail_delivery_mode,
incoterm=self.cpt_incoterm,
specialise_value=self.business_process,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
......@@ -827,6 +817,7 @@ class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
price_currency_value=currency,
delivery_mode=self.mail_delivery_mode,
incoterm=self.cpt_incoterm,
specialise_value=self.business_process,
title='Order')
first_order_line = order.newContent(
portal_type='Sale Order Line',
......
#############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Aurelien Calonne <aurel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
import transaction
from DateTime import DateTime
from zLOG import LOG
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Testing import ZopeTestCase
from Products.ERP5.tests.testAccounting import AccountingTestCase
from AccessControl.SecurityManagement import newSecurityManager
QUIET = False
run_all_test = True
def printAndLog(msg):
"""
A utility function to print a message
to the standard output and to the LOG
at the same time
"""
msg = str(msg)
ZopeTestCase._print('\n ' + msg)
LOG('Testing... ', 0, msg)
class TestConversionInSimulation(AccountingTestCase,ERP5TypeTestCase):
username = 'username'
default_region = "europe/west/france"
vat_gap = 'fr/pcg/4/44/445/4457/44571'
vat_rate = 0.196
sale_gap = 'fr/pcg/7/70/707/7071/70712'
customer_gap = 'fr/pcg/4/41/411'
mail_delivery_mode = 'by_mail'
cpt_incoterm = 'cpt'
unit_piece_quantity_unit = 'unit/piece'
mass_quantity_unit = 'mass/kg'
# (account_id, account_gap, account_type)
account_definition_list = (
('receivable_vat', vat_gap, 'liability/payable/collected_vat',),
('sale', sale_gap, 'income'),
('customer', customer_gap, 'asset/receivable'),
('refundable_vat', vat_gap, 'asset/receivable/refundable_vat'),
('purchase', sale_gap, 'expense'),
('supplier', customer_gap, 'liability/payable'),
)
# (line_id, source_account_id, destination_account_id, line_quantity)
transaction_line_definition_list = (
('income', 'sale', 'purchase', 1.0),
('receivable', 'customer', 'supplier', -1.0 - vat_rate),
('collected_vat', 'receivable_vat', 'refundable_vat', vat_rate),
)
@UnrestrictedMethod
def createCategories(self):
"""Create the categories for our test. """
for cat_string in self.getNeededCategoryList() :
base_cat = cat_string.split("/")[0]
path = self.getPortal().portal_categories[base_cat]
for cat in cat_string.split("/")[1:] :
if not cat in path.objectIds() :
path = path.newContent(
portal_type='Category',
id=cat,)
else:
path = path[cat]
# check categories have been created
for cat_string in self.getNeededCategoryList() :
self.assertNotEquals(None,
self.getCategoryTool().restrictedTraverse(cat_string),
cat_string)
def getNeededCategoryList(self):
"""return a list of categories that should be created."""
return ('region/%s' % self.default_region,
'gap/%s' % self.vat_gap,
'gap/%s' % self.sale_gap,
'gap/%s' % self.customer_gap,
'delivery_mode/%s' % self.mail_delivery_mode,
'incoterm/%s' % self.cpt_incoterm,
'quantity_unit/%s' % self.unit_piece_quantity_unit,
'quantity_unit/%s' % self.mass_quantity_unit,
)
def _solveDivergence(self, obj, property, decision, group='line'):
"""
Check if simulation movement are disconnected
"""
kw = {'%s_group_listbox' % group:{}}
for divergence in obj.getDivergenceList():
if divergence.getProperty('tested_property') != property:
continue
sm_url = divergence.getProperty('simulation_movement').getRelativeUrl()
kw['line_group_listbox']['%s&%s' % (sm_url, property)] = {
'choice':decision}
self.portal.portal_workflow.doActionFor(
obj,
'solve_divergence_action',
**kw)
def afterSetUp(self):
self.createCategories()
self.validateRules()
self.login()
def beforeTearDown(self):
transaction.abort()
# clear modules if necessary
currency_list = ('euro', 'yen', 'usd')
module = self.portal.currency_module
module.manage_delObjects([x for x in module.objectIds()
if x not in currency_list])
for currency_id in currency_list:
currency = self.currency_module._getOb(currency_id, None)
if currency is not None:
currency.manage_delObjects([x.getId() for x in
currency.objectValues(
portal_type='Currency Exchange Line')])
transaction.commit()
self.tic()
def login(self,name=username, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users
uf._doAddUser(self.username, '', ['Assignee', 'Assignor',
'Author'], [])
user = uf.getUserById(self.username).__of__(uf)
newSecurityManager(None, user)
def getBusinessTemplateList(self):
"""
Return the list of business templates we need to run the test.
This method is called during the initialization of the unit test by
the unit test framework in order to know which business templates
need to be installed to run the test on.
"""
return ('erp5_base',
'erp5_pdm',
'erp5_trade',
'erp5_accounting',
'erp5_accounting_ui_test',
'erp5_invoicing',
'erp5_simplified_invoicing'
)
@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.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,
source_value=account_module[line_source_id],
destination_value=account_module[line_destination_id])
invoice_rule.validate()
transaction.commit()
self.tic()
def test_01_simulation_movement_destination_asset_price(self,quiet=0,
run=run_all_test):
"""
tests that when resource on simulation movements is different
from the price currency of the destination section, that
destination_asset_price is set on the movement
"""
if not run: return
if not quiet:
printAndLog('test_01_simulation_movement_destination_asset_price')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transactio
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
quantity=1,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_applied_rule = order.getCausalityRelatedValue(
portal_type='Applied Rule')
order_movement = related_applied_rule.contentValues()[0]
delivery_applied_rule = order_movement.contentValues()[0]
delivery_movement = delivery_applied_rule.contentValues()[0]
invoice_applied_rule = delivery_movement.contentValues()[0]
invoice_movement = invoice_applied_rule.contentValues()[0]
invoice_transaction_applied_rule = invoice_movement.contentValues()[0]
invoice_transaction_movement_1 =\
invoice_transaction_applied_rule.contentValues()[0]
self.assertEquals(currency,
invoice_transaction_movement_1.getResourceValue())
self.assertEquals(currency,
delivery_movement.getPriceCurrencyValue())
self.assertEquals\
(invoice_transaction_movement_1.getDestinationTotalAssetPrice(),
round(655.957*delivery_movement.getTotalPrice()))
self.assertEquals\
(invoice_transaction_movement_1.getSourceTotalAssetPrice(),
None)
invoice_transaction_movement_2 =\
invoice_transaction_applied_rule.contentValues()[1]
self.assertEquals(currency,
invoice_transaction_movement_2.getResourceValue())
self.assertEquals(currency,
delivery_movement.getPriceCurrencyValue())
self.assertEquals\
(invoice_transaction_movement_2.getDestinationTotalAssetPrice(),
round(655.957*delivery_movement.getTotalPrice()))
def test_01_simulation_movement_source_asset_price(self,quiet=0,
run=run_all_test):
"""
tests that when resource on simulation movements is different
from the price currency of the source section, that
source_asset_price is set on the movement
"""
if not run: return
if not quiet:
printAndLog('test_01_simulation_movement_source_asset_price')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transactio
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
quantity=1,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_applied_rule = order.getCausalityRelatedValue(
portal_type='Applied Rule')
order_movement = related_applied_rule.contentValues()[0]
delivery_applied_rule = order_movement.contentValues()[0]
delivery_movement = delivery_applied_rule.contentValues()[0]
invoice_applied_rule = delivery_movement.contentValues()[0]
invoice_movement = invoice_applied_rule.contentValues()[0]
invoice_transaction_applied_rule = invoice_movement.contentValues()[0]
invoice_transaction_movement =\
invoice_transaction_applied_rule.contentValues()[0]
self.assertEquals(currency,
invoice_transaction_movement.getResourceValue())
self.assertEquals(currency,
delivery_movement.getPriceCurrencyValue())
self.assertEquals\
(invoice_transaction_movement.getSourceTotalAssetPrice(),
round(655.957*delivery_movement.getTotalPrice()))
self.assertEquals\
(invoice_transaction_movement.getDestinationTotalAssetPrice(),
None)
def test_01_destination_total_asset_price_on_accounting_lines(self,quiet=0,
run=run_all_test):
"""
tests that the delivery builder of the invoice transaction lines
copies the destination asset price on the accounting_lines of the invoice
"""
if not run: return
if not quiet:
printAndLog(
'test_01_destination_total_asset_price_on_accounting_lines')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
quantity=1,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_packing_list = order.getCausalityRelatedValue(
portal_type='Sale Packing List')
self.assertNotEquals(related_packing_list, None)
related_packing_list.start()
related_packing_list.stop()
transaction.commit()
self.tic()
related_applied_rule = order.getCausalityRelatedValue(
portal_type='Applied Rule')
order_movement = related_applied_rule.contentValues()[0]
delivery_applied_rule = order_movement.contentValues()[0]
delivery_movement = delivery_applied_rule.contentValues()[0]
related_invoice = related_packing_list.getCausalityRelatedValue(
portal_type='Sale Invoice Transaction')
self.assertNotEquals(related_invoice, None)
related_invoice.start()
transaction.commit()
self.tic()
line_list= related_invoice.contentValues(
portal_type=self.portal.getPortalAccountingMovementTypeList())
self.assertNotEquals(line_list, None)
for line in line_list:
self.assertEquals(line.getDestinationTotalAssetPrice(),
round(655.957*delivery_movement.getTotalPrice()))
def test_01_diverged_sale_packing_list_destination_total_asset_price(
self,quiet=0,run=run_all_test):
"""
tests that when the sale packing list is divergent on the quantity and
that the resource on simulation movements is different
from the price currency of the source section,
source_asset_price is updated as we solve the divergence and
accept the decision
"""
if not run: return
if not quiet:
printAndLog(
'test_01_diverged_sale_packing_list_destination_total_asset_price')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
quantity=5,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_packing_list = order.getCausalityRelatedValue(
portal_type='Sale Packing List')
self.assertNotEquals(related_packing_list, None)
related_packing_list_line_list=related_packing_list.getMovementList()
related_packing_list_line= related_packing_list_line_list[0]
self.assertEquals(related_packing_list_line.getQuantity(),5.0)
old_destination_asset_price = \
round(655.957*related_packing_list_line.getTotalPrice())
related_packing_list_line.edit(quantity=3.0)
transaction.commit()
self.tic()
self.assertEquals(related_packing_list.getCausalityState(),
'diverged')
self._solveDivergence(related_packing_list, 'quantity', 'accept')
transaction.commit()
self.tic()
related_packing_list.start()
related_packing_list.stop()
transaction.commit()
self.tic()
related_applied_rule = order.getCausalityRelatedValue(
portal_type='Applied Rule')
order_movement = related_applied_rule.contentValues()[0]
delivery_applied_rule = order_movement.contentValues()[0]
delivery_movement = delivery_applied_rule.contentValues()[0]
invoice_applied_rule = delivery_movement.contentValues()[0]
invoice_movement = invoice_applied_rule.contentValues()[0]
invoice_transaction_applied_rule = invoice_movement.contentValues()[0]
invoice_transaction_movement =\
invoice_transaction_applied_rule.contentValues()[0]
self.assertEquals(
invoice_transaction_movement.getDestinationTotalAssetPrice(),
old_destination_asset_price *(3.0/5.0))
def test_01_diverged_purchase_packing_list_source_total_asset_price(
self,quiet=0,run=run_all_test):
"""
tests that when the purchase packing list is divergent on the quantity
and that the resource on simulation movements is different
from the price currency of the destination section,
destination_asset_price is updated as we solve the divergence and
accept the decision
"""
if not run: return
if not quiet:
printAndLog(
'test_01_diverged_purchase_packing_list_source_total_asset_price')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
order = self.portal.purchase_order_module.newContent(
portal_type='Purchase Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
title='Order')
order_line = order.newContent(portal_type='Purchase Order Line',
resource_value=resource,
quantity=5,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_packing_list = order.getCausalityRelatedValue(
portal_type='Purchase Packing List')
self.assertNotEquals(related_packing_list, None)
related_packing_list_line_list=related_packing_list.getMovementList()
related_packing_list_line= related_packing_list_line_list[0]
self.assertEquals(related_packing_list_line.getQuantity(),5.0)
old_source_asset_price = \
round(655.957*related_packing_list_line.getTotalPrice())
related_packing_list_line.edit(quantity=3.0)
transaction.commit()
self.tic()
self.assertEquals(related_packing_list.getCausalityState(),
'diverged')
self._solveDivergence(related_packing_list, 'quantity','accept')
transaction.commit()
self.tic()
related_packing_list.start()
related_packing_list.stop()
transaction.commit()
self.tic()
related_applied_rule = order.getCausalityRelatedValue(
portal_type='Applied Rule')
order_movement = related_applied_rule.contentValues()[0]
delivery_applied_rule = order_movement.contentValues()[0]
delivery_movement = delivery_applied_rule.contentValues()[0]
invoice_applied_rule = delivery_movement.contentValues()[0]
invoice_movement = invoice_applied_rule.contentValues()[0]
invoice_transaction_applied_rule = invoice_movement.contentValues()[0]
invoice_transaction_movement =\
invoice_transaction_applied_rule.contentValues()[0]
self.assertEquals(invoice_transaction_movement.\
getSourceTotalAssetPrice(),
old_source_asset_price *(3.0/5.0))
def test_01_delivery_mode_on_sale_packing_list_and_invoice(
self,quiet=0,run=run_all_test):
"""
tests that when the sale packing list is divergent on the quantity and
that the resource on simulation movements is different
from the price currency of the source section,
source_asset_price is updated as we solve the divergence and
accept the decision
"""
if not run: return
if not quiet:
printAndLog(
'test_01_delivery_mode_on_sale_packing_list_and_invoice')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
new_currency = \
self.portal.currency_module.newContent(portal_type='Currency')
new_currency.setReference('XOF')
new_currency.setTitle('Francs CFA')
new_currency.setBaseUnitQuantity(1.00)
transaction.commit()
self.tic()#execute transaction
x_curr_ex_line = currency.newContent(
portal_type='Currency Exchange Line',
price_currency=new_currency.getRelativeUrl())
x_curr_ex_line.setTitle('Euro to Francs CFA')
x_curr_ex_line.setBasePrice(655.957)
x_curr_ex_line.setStartDate(DateTime(2008,10,21))
x_curr_ex_line.setStopDate(DateTime(2008,10,22))
x_curr_ex_line.validate()
self.createInvoiceTransactionRule(currency)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
price_currency=new_currency.getRelativeUrl(),
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
delivery_mode=self.mail_delivery_mode,
incoterm=self.cpt_incoterm,
title='Order')
order_line = order.newContent(portal_type='Sale Order Line',
resource_value=resource,
quantity=5,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_packing_list = order.getCausalityRelatedValue(
portal_type='Sale Packing List')
self.assertNotEquals(related_packing_list, None)
self.assertEquals(related_packing_list.getDeliveryMode(),
order.getDeliveryMode())
self.assertEquals(related_packing_list.getIncoterm(),
order.getIncoterm())
related_packing_list.start()
related_packing_list.stop()
transaction.commit()
self.tic()
related_invoice = related_packing_list.getCausalityRelatedValue(
portal_type='Sale Invoice Transaction')
self.assertNotEquals(related_invoice, None)
self.assertEquals(related_invoice.getDeliveryMode(),
order.getDeliveryMode())
self.assertEquals(related_invoice.getIncoterm(),
order.getIncoterm())
def test_01_quantity_unit_on_sale_packing_list(
self,quiet=0,run=run_all_test):
"""
tests that when a resource uses different quantity unit that the
"""
if not run: return
if not quiet:
printAndLog(
'test_01_quantity_unit_on_sale_packing_list')
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource',
product_line='apparel')
resource.setQuantityUnitList([self.unit_piece_quantity_unit,
self.mass_quantity_unit])
currency = self.portal.currency_module.newContent(
portal_type='Currency',
title='euro')
currency.setBaseUnitQuantity(0.01)
transaction.commit()
self.tic()#execute transaction
client = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Client',
default_address_region=self.default_region)
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Vendor',
default_address_region=self.default_region)
order = self.portal.sale_order_module.newContent(
portal_type='Sale Order',
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008,10, 21),
price_currency_value=currency,
delivery_mode=self.mail_delivery_mode,
incoterm=self.cpt_incoterm,
title='Order')
first_order_line = order.newContent(
portal_type='Sale Order Line',
resource_value=resource,
quantity_unit = self.unit_piece_quantity_unit,
quantity=5,
price=3)
second_order_line = order.newContent(
portal_type='Sale Order Line',
resource_value=resource,
quantity_unit=self.mass_quantity_unit,
quantity=1.5,
price=2)
order.confirm()
transaction.commit()
self.tic()
related_packing_list = order.getCausalityRelatedValue(
portal_type='Sale Packing List')
self.assertNotEquals(related_packing_list, None)
movement_list = related_packing_list.getMovementList()
movement_list.sort(key=lambda x:x.getCausalityId())
self.assertEquals(len(movement_list),2)
self.assertEquals(movement_list[0].getQuantityUnit(),
first_order_line.getQuantityUnit())
self.assertEquals(movement_list[1].getQuantityUnit(),
second_order_line.getQuantityUnit())
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConversionInSimulation))
return suite
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