Commit ea6834bf authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: testSlapOSAccountingRule stop using hardcoded trade condition

parent 2ae97bbc
...@@ -11,7 +11,6 @@ from erp5.component.module.DateUtils import addToDate ...@@ -11,7 +11,6 @@ from erp5.component.module.DateUtils import addToDate
from erp5.component.document.SimulationMovement import SimulationMovement from erp5.component.document.SimulationMovement import SimulationMovement
import transaction import transaction
AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL = 'sale_trade_condition_module/slapos_aggregated_trade_condition_v3'
def getSimulationStatePlanned(self, *args, **kwargs): def getSimulationStatePlanned(self, *args, **kwargs):
return 'planned' return 'planned'
...@@ -36,14 +35,13 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin): ...@@ -36,14 +35,13 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin):
try: try:
SimulationMovement.getSimulationState = getSimulationStatePlanned SimulationMovement.getSimulationState = getSimulationStatePlanned
source = self.portal.person_module.template_member\ resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
.Base_createCloneDocument(batch_mode=1) project = aggregate.getFollowUpValue()
destination = self.portal.person_module.template_member\ trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
.Base_createCloneDocument(batch_mode=1) source = trade_condition.getSourceSectionValue()
project = self.addProject() destination = aggregate.getDestinationSectionValue()
aggregate = self.portal.instance_tree_module\ business_process = trade_condition.getSpecialiseValue()
.template_instance_tree.Base_createCloneDocument(batch_mode=1)
resource = self.portal.service_module.slapos_instance_subscription
start_date = DateTime('2011/02/16') start_date = DateTime('2011/02/16')
stop_date = DateTime('2011/03/16') stop_date = DateTime('2011/03/16')
...@@ -68,18 +66,21 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin): ...@@ -68,18 +66,21 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin):
stop_date=stop_date, stop_date=stop_date,
base_contribution_list=['base_amount/invoicing/discounted', base_contribution_list=['base_amount/invoicing/discounted',
'base_amount/invoicing/taxable'], 'base_amount/invoicing/taxable'],
price_currency='currency_module/EUR', price_currency=trade_condition.getPriceCurrency(),
use='trade/sale', use='trade/sale',
ledger='automated', ledger='automated',
trade_phase='slapos/invoicing', trade_phase='slapos/invoicing',
quantity_unit='unit/piece', quantity_unit='unit/piece',
specialise= specialise=trade_condition.getRelativeUrl(),
AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL, causality_list=[
causality_list=['business_process_module/slapos_aggregated_business_process/invoice_path', 'business_process_module/slapos_aggregated_business_process/invoice'], '%s/invoice_path' % business_process.getRelativeUrl(),
'%s/invoice' % business_process.getRelativeUrl()
],
delivery_value=self.portal.accounting_module.newContent( delivery_value=self.portal.accounting_module.newContent(
portal_type='Sale Invoice Transaction').newContent( portal_type='Sale Invoice Transaction').newContent(
portal_type='Invoice Line') portal_type='Invoice Line')
) )
self.tic()
self.assertEqual('planned', self.assertEqual('planned',
root_simulation_movement.getSimulationState()) root_simulation_movement.getSimulationState())
...@@ -108,9 +109,9 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin): ...@@ -108,9 +109,9 @@ class TestDefaultInvoiceTransactionRule(SlapOSTestCaseMixin):
portal_type='Simulation Movement') portal_type='Simulation Movement')
self.assertEqual(2, len(simulation_movement_list)) self.assertEqual(2, len(simulation_movement_list))
debit_movement_list = [q for q in simulation_movement_list if \ debit_movement_list = [q for q in simulation_movement_list if \
q.getCausality() == 'business_process_module/slapos_aggregated_business_process/account_debit_path'] q.getCausality() == '%s/account_debit_path' % business_process.getRelativeUrl()]
credit_movement_list = [q for q in simulation_movement_list if \ credit_movement_list = [q for q in simulation_movement_list if \
q.getCausality() == 'business_process_module/slapos_aggregated_business_process/account_credit_path'] q.getCausality() == '%s/account_credit_path' % business_process.getRelativeUrl()]
self.assertEqual(1, len(debit_movement_list)) self.assertEqual(1, len(debit_movement_list))
self.assertEqual(1, len(credit_movement_list)) self.assertEqual(1, len(credit_movement_list))
debit_movement = debit_movement_list[0] debit_movement = debit_movement_list[0]
...@@ -175,12 +176,13 @@ class TestDefaultInvoiceRule(SlapOSTestCaseMixin): ...@@ -175,12 +176,13 @@ class TestDefaultInvoiceRule(SlapOSTestCaseMixin):
try: try:
SimulationMovement.getSimulationState = getSimulationStatePlanned SimulationMovement.getSimulationState = getSimulationStatePlanned
source = self.portal.person_module.template_member\ resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
.Base_createCloneDocument(batch_mode=1) project = aggregate.getFollowUpValue()
destination = self.portal.person_module.template_member\ trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
.Base_createCloneDocument(batch_mode=1) source = trade_condition.getSourceSectionValue()
project = self.addProject() destination = aggregate.getDestinationSectionValue()
resource = self.portal.service_module.slapos_account_validation business_process = trade_condition.getSpecialiseValue()
start_date = DateTime('2011/02/16') start_date = DateTime('2011/02/16')
stop_date = DateTime('2011/02/16') stop_date = DateTime('2011/02/16')
...@@ -209,9 +211,11 @@ class TestDefaultInvoiceRule(SlapOSTestCaseMixin): ...@@ -209,9 +211,11 @@ class TestDefaultInvoiceRule(SlapOSTestCaseMixin):
trade_phase='slapos/invoicing', trade_phase='slapos/invoicing',
ledger='automated', ledger='automated',
quantity_unit='unit/piece', quantity_unit='unit/piece',
specialise=AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL, specialise=trade_condition.getRelativeUrl(),
causality_list=['business_process_module/slapos_aggregated_business_process/invoice_path', causality_list=[
'business_process_module/slapos_aggregated_business_process/invoice']) '%s/invoice_path' % business_process.getRelativeUrl(),
'%s/invoice' % business_process.getRelativeUrl()
])
self.assertEqual('planned', self.assertEqual('planned',
root_simulation_movement.getSimulationState()) root_simulation_movement.getSimulationState())
...@@ -252,14 +256,13 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin): ...@@ -252,14 +256,13 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin):
try: try:
SimulationMovement.getSimulationState = getSimulationStatePlanned SimulationMovement.getSimulationState = getSimulationStatePlanned
source = self.portal.person_module.template_member\ resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
.Base_createCloneDocument(batch_mode=1) project = aggregate.getFollowUpValue()
destination = self.portal.person_module.template_member\ trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
.Base_createCloneDocument(batch_mode=1) source = trade_condition.getSourceSectionValue()
project = self.addProject() destination = aggregate.getDestinationSectionValue()
aggregate = self.portal.instance_tree_module\ business_process = trade_condition.getSpecialiseValue()
.template_instance_tree.Base_createCloneDocument(batch_mode=1)
resource = self.portal.service_module.slapos_instance_subscription
start_date = DateTime('2011/02/16') start_date = DateTime('2011/02/16')
stop_date = DateTime('2011/03/16') stop_date = DateTime('2011/03/16')
...@@ -289,8 +292,11 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin): ...@@ -289,8 +292,11 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin):
trade_phase='slapos/delivery', trade_phase='slapos/delivery',
ledger='automated', ledger='automated',
quantity_unit='unit/piece', quantity_unit='unit/piece',
specialise=AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL, specialise=trade_condition.getRelativeUrl(),
causality_list=['business_process_module/slapos_aggregated_business_process/delivery_path', 'business_process_module/slapos_aggregated_business_process/deliver']) causality_list=[
'%s/delivery_path' % business_process.getRelativeUrl(),
'%s/deliver' % business_process.getRelativeUrl()
])
self.assertEqual('planned', self.assertEqual('planned',
root_simulation_movement.getSimulationState()) root_simulation_movement.getSimulationState())
...@@ -354,7 +360,10 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin): ...@@ -354,7 +360,10 @@ class TestDefaultInvoicingRule(SlapOSTestCaseMixin):
simulation_movement.getQuantityUnit()) simulation_movement.getQuantityUnit())
self.assertEqual(root_simulation_movement.getSpecialise(), self.assertEqual(root_simulation_movement.getSpecialise(),
simulation_movement.getSpecialise()) simulation_movement.getSpecialise())
self.assertEqual(['business_process_module/slapos_aggregated_business_process/invoice_path', 'business_process_module/slapos_aggregated_business_process/invoice'], simulation_movement.getCausalityList()) self.assertEqual([
'%s/invoice_path' % business_process.getRelativeUrl(),
'%s/invoice' % business_process.getRelativeUrl()
], simulation_movement.getCausalityList())
# check children rules' type # check children rules' type
child_applied_rule_type_list = [q.getSpecialiseReference() for q in \ child_applied_rule_type_list = [q.getSpecialiseReference() for q in \
simulation_movement.contentValues(portal_type='Applied Rule')] simulation_movement.contentValues(portal_type='Applied Rule')]
...@@ -379,12 +388,14 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin): ...@@ -379,12 +388,14 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin):
try: try:
SimulationMovement.getSimulationState = getSimulationStatePlanned SimulationMovement.getSimulationState = getSimulationStatePlanned
source = self.portal.person_module.template_member\ _, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
.Base_createCloneDocument(batch_mode=1) project = aggregate.getFollowUpValue()
destination = self.portal.person_module.template_member\ trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
.Base_createCloneDocument(batch_mode=1) source = trade_condition.getSourceSectionValue()
project = self.addProject() destination = aggregate.getDestinationSectionValue()
resource = self.portal.currency_module.EUR business_process = trade_condition.getSpecialiseValue()
resource = trade_condition.getPriceCurrencyValue()
start_date = DateTime('2011/02/16') start_date = DateTime('2011/02/16')
stop_date = DateTime('2011/03/16') stop_date = DateTime('2011/03/16')
...@@ -410,8 +421,10 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin): ...@@ -410,8 +421,10 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin):
trade_phase='slapos/accounting', trade_phase='slapos/accounting',
ledger='automated', ledger='automated',
quantity_unit='unit/piece', quantity_unit='unit/piece',
specialise=AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL, specialise=trade_condition.getRelativeUrl(),
causality_list=['business_process_module/slapos_aggregated_business_process/account'], causality_list=[
'%s/account' % business_process.getRelativeUrl()
],
delivery_value=self.portal.accounting_module.newContent( delivery_value=self.portal.accounting_module.newContent(
portal_type='Sale Invoice Transaction').newContent( portal_type='Sale Invoice Transaction').newContent(
portal_type='Invoice Line') portal_type='Invoice Line')
...@@ -441,26 +454,13 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin): ...@@ -441,26 +454,13 @@ class TestDefaultPaymentRule(SlapOSTestCaseMixin):
class TestHostingSubscriptionSimulation(SlapOSTestCaseMixin): class TestHostingSubscriptionSimulation(SlapOSTestCaseMixin):
def _prepare(self): def _prepare(self):
""" software_product, _, _, _, _, self.instance_tree = self.bootstrapAllocableInstanceTree(is_accountable=True)
person = self.portal.person_module.template_member\ project = software_product.getFollowUpValue()
.Base_createCloneDocument(batch_mode=1)
project = self.addProject()
self.instance_tree = self.portal.instance_tree_module\
.template_instance_tree.Base_createCloneDocument(batch_mode=1)
self.instance_tree.edit(
destination_section_value=person,
follow_up_value=project
)
self.portal.portal_workflow._jumpToStateFor(self.instance_tree, 'validated')
"""
software_product, _, _, _, _, self.instance_tree = self.bootstrapAllocableInstanceTree()
#person = instance_tree.getDestinationSectionValue()
sale_supply = self.portal.sale_supply_module.newContent( sale_supply = self.portal.sale_supply_module.newContent(
portal_type="Sale Supply", portal_type="Sale Supply",
destination_project_value=software_product.getFollowUpValue(), destination_project_value=project,
price_currency="currency_module/EUR" price_currency=project.Project_getAccountingCurrency()
) )
# XXX Put price in sale supply module
sale_supply.newContent( sale_supply.newContent(
portal_type="Sale Supply Line", portal_type="Sale Supply Line",
base_price=9, base_price=9,
...@@ -469,9 +469,11 @@ class TestHostingSubscriptionSimulation(SlapOSTestCaseMixin): ...@@ -469,9 +469,11 @@ class TestHostingSubscriptionSimulation(SlapOSTestCaseMixin):
sale_supply.validate() sale_supply.validate()
self.tic() self.tic()
open_order = self.instance_tree.InstanceTree_requestUpdateOpenSaleOrder( trade_condition = project.getSpecialiseValue()
specialise="sale_trade_condition_module/default_subscription_trade_condition" # This test expect no accounting.
) # Disable this by not setting a source section on the trade condition
trade_condition.edit(source_section=None)
open_order = self.instance_tree.InstanceTree_requestUpdateOpenSaleOrder()
self.tic() self.tic()
self.initial_date = DateTime('2011/02/16') self.initial_date = DateTime('2011/02/16')
stop_date = DateTime('2011/04/16') stop_date = DateTime('2011/04/16')
...@@ -723,14 +725,14 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin): ...@@ -723,14 +725,14 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin):
try: try:
SimulationMovement.getSimulationState = getSimulationStatePlanned SimulationMovement.getSimulationState = getSimulationStatePlanned
source = self.portal.person_module.template_member\ resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
.Base_createCloneDocument(batch_mode=1) project = aggregate.getFollowUpValue()
destination = self.portal.person_module.template_member\ trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
.Base_createCloneDocument(batch_mode=1) source = trade_condition.getSourceSectionValue()
project = self.addProject() destination = aggregate.getDestinationSectionValue()
aggregate = self.portal.instance_tree_module\ price_currency = trade_condition.getPriceCurrencyValue()
.template_instance_tree.Base_createCloneDocument(batch_mode=1) business_process = trade_condition.getSpecialiseValue()
resource = self.portal.service_module.slapos_instance_subscription
start_date = DateTime('2011/02/16') start_date = DateTime('2011/02/16')
stop_date = DateTime('2011/03/16') stop_date = DateTime('2011/03/16')
...@@ -755,13 +757,16 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin): ...@@ -755,13 +757,16 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin):
stop_date=stop_date, stop_date=stop_date,
base_contribution_list=['base_amount/invoicing/discounted', base_contribution_list=['base_amount/invoicing/discounted',
'base_amount/invoicing/taxable'], 'base_amount/invoicing/taxable'],
price_currency='currency_module/EUR', price_currency_value=price_currency,
use='trade/sale', use='trade/sale',
trade_phase='slapos/invoicing', trade_phase='slapos/invoicing',
ledger='automated', ledger='automated',
quantity_unit='unit/piece', quantity_unit='unit/piece',
specialise=AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL, specialise=trade_condition.getRelativeUrl(),
causality_list=['business_process_module/slapos_aggregated_business_process/invoice_path', 'business_process_module/slapos_aggregated_business_process/invoice'], causality_list=[
'%s/invoice_path' % business_process.getRelativeUrl(),
'%s/invoice' % business_process.getRelativeUrl()
],
delivery_value=self.portal.accounting_module.newContent( delivery_value=self.portal.accounting_module.newContent(
portal_type='Sale Invoice Transaction').newContent( portal_type='Sale Invoice Transaction').newContent(
portal_type='Invoice Line') portal_type='Invoice Line')
...@@ -836,36 +841,33 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin): ...@@ -836,36 +841,33 @@ class TestDefaultTradeModelRule(SlapOSTestCaseMixin):
.original_getSimulationState .original_getSimulationState
class TestDefaultDeliveryRule(SlapOSTestCaseMixin): class TestDefaultDeliveryRule(SlapOSTestCaseMixin):
trade_condition = AGGREGATE_SALE_TRADE_CONDITION_RELATIVE_URL
def test(self): def test(self):
def newArrow(): resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
return self.portal.organisation_module.newContent( project = aggregate.getFollowUpValue()
portal_type='Organisation').getRelativeUrl() trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
project = self.addProject() source = trade_condition.getSourceSectionValue()
destination = aggregate.getDestinationSectionValue()
price_currency = trade_condition.getPriceCurrencyValue()
delivery = self.portal.sale_packing_list_module.newContent( delivery = self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List', portal_type='Sale Packing List',
source=newArrow(), source_value=source,
destination=newArrow(), destination_value=destination,
source_section=newArrow(), source_section_value=source,
destination_section=newArrow(), destination_section_value=destination,
destination_project_value=project, destination_project_value=project,
price_currency='currency_module/EUR', price_currency_value=price_currency,
specialise=self.trade_condition, specialise_value=trade_condition,
start_date=DateTime('2012/01/01'), start_date=DateTime('2012/01/01'),
stop_date=DateTime('2012/02/02'), stop_date=DateTime('2012/02/02'),
ledger='automated' ledger='automated'
) )
line = delivery.newContent(portal_type='Sale Packing List Line', line = delivery.newContent(portal_type='Sale Packing List Line',
resource=self.portal.service_module.newContent( resource_value=resource,
portal_type='Service').getRelativeUrl(),
use='trade/sale', use='trade/sale',
quantity_unit='unit/piece', quantity_unit='unit/piece',
aggregate_list=[ aggregate_value=aggregate,
self.portal.instance_tree_module.newContent(
portal_type='Instance Tree').getRelativeUrl(),
self.portal.service_module.newContent(
portal_type='Service').getRelativeUrl()
],
base_contribution_list=['base_amount/invoicing/discounted', base_contribution_list=['base_amount/invoicing/discounted',
'base_amount/invoicing/taxable'], 'base_amount/invoicing/taxable'],
price=1.23, price=1.23,
...@@ -932,35 +934,32 @@ class TestDefaultDeliveryRule(SlapOSTestCaseMixin): ...@@ -932,35 +934,32 @@ class TestDefaultDeliveryRule(SlapOSTestCaseMixin):
class TestDefaultDeliveryRuleConsumption(SlapOSTestCaseMixin): class TestDefaultDeliveryRuleConsumption(SlapOSTestCaseMixin):
def test(self): def test(self):
def newArrow(): resource, _, _, _, _, aggregate = self.bootstrapAllocableInstanceTree(is_accountable=True)
return self.portal.organisation_module.newContent( project = aggregate.getFollowUpValue()
portal_type='Organisation').getRelativeUrl() trade_condition = aggregate.getFollowUpValue().getSpecialiseValue()
project = self.addProject() source = trade_condition.getSourceSectionValue()
destination = aggregate.getDestinationSectionValue()
price_currency = trade_condition.getPriceCurrencyValue()
delivery = self.portal.sale_packing_list_module.newContent( delivery = self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List', portal_type='Sale Packing List',
source=newArrow(), source_value=source,
destination=newArrow(), destination_value=destination,
source_section=newArrow(), source_section_value=source,
destination_section=newArrow(), # Do not set any *_section if no invoice are required
#destination_section_value=destination,
destination_project_value=project, destination_project_value=project,
price_currency='currency_module/EUR', price_currency_value=price_currency,
specialise='sale_trade_condition_module/slapos_consumption_trade_' specialise_value=trade_condition,
'condition',
start_date=DateTime('2012/01/01'), start_date=DateTime('2012/01/01'),
stop_date=DateTime('2012/02/02'), stop_date=DateTime('2012/02/02'),
ledger='automated' ledger='automated'
) )
delivery.newContent(portal_type='Sale Packing List Line', delivery.newContent(portal_type='Sale Packing List Line',
resource=self.portal.service_module.newContent( resource_value=resource,
portal_type='Service').getRelativeUrl(),
use='trade/sale', use='trade/sale',
quantity_unit='unit/piece', quantity_unit='unit/piece',
aggregate_list=[ aggregate_value=aggregate,
self.portal.instance_tree_module.newContent(
portal_type='Instance Tree').getRelativeUrl(),
self.portal.service_module.newContent(
portal_type='Service').getRelativeUrl()
],
base_contribution_list=['base_amount/invoicing/discounted', base_contribution_list=['base_amount/invoicing/discounted',
'base_amount/invoicing/taxable'], 'base_amount/invoicing/taxable'],
price=.0, price=.0,
......
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