Commit 1214a69b authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: testSlapOSAccountingRule stop using hardcoded trade condition

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