Commit ecf6e6f4 authored by Łukasz Nowak's avatar Łukasz Nowak

- use BPMRule.expand

 - move logic to prevision list


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28165 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 159dd4b6
......@@ -148,9 +148,55 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
context_movement.getPrice(0.0)) *
accounting_rule_cell_line.getQuantity(),
'price': 1,
'force_update': 1,
'causality_value': business_path,
}
from Products.ERP5Type.Document import newTempSimulationMovement
temporary_movement = newTempSimulationMovement(self.getPortalObjec(),
'1', **prevision_line)
#set asset_price on movement when resource is different from price
#currency of the source/destination section
if resource is not None:
currency = self.restrictedTraverse(resource)
currency_url = currency.getRelativeUrl()
destination_section = prevision_line['destination_section']
if destination_section is not None:
destination_currency_url = self.restrictedTraverse(
destination_section).getProperty('price_currency', None)
else:
destination_currency_url = None
if destination_currency_url is not None \
and currency_url != destination_currency_url:
precision = destination_section.getPriceCurrencyValue() \
.getQuantityPrecision()
destination_exchange_ratio = currency.getPrice(
context=temporary_movement.asContext(
categories=['price_currency/%s' % destination_currency_url,
'resource/%s' % currency_url],
start_date=temporary_movement.getStartDate()))
if destination_exchange_ratio is not None:
prevision_line.update(destination_total_asset_price=round(
(destination_exchange_ratio*
applied_rule.getParentValue().getTotalPrice()),precision))
source_section = prevision_line['source_section']
if source_section is not None:
source_currency_url = self.restrictedTraverse(
'source_section').getProperty('price_currency', None)
else:
source_currency_url = None
if source_currency_url is not None \
and currency_url != source_currency_url:
precision = source_section.getPriceCurrencyValue() \
.getQuantityPrecision()
source_exchange_ratio = currency.getPrice(
context=temporary_movement.asContext(
categories=['price_currency/%s' % source_currency_url,
'resource/%s' % currency_url],
start_date=temporary_movement.getStartDate()))
if source_exchange_ratio is not None:
prevision_line.update(source_total_asset_price = round(
source_exchange_ratio*applied_rule.getParentValue().getTotalPrice(),
precision))
if accounting_rule_cell_line.hasProperty(
'generate_prevision_script_id'):
......@@ -161,86 +207,6 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
prevision_list.append(prevision_line)
return prevision_list
security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule, force=0, **kw):
"""
Expands the rule:
- generate a list of previsions
- compare the prevision with existing children
- get the list of existing movements (immutable, mutable, deletable)
- compute the difference between prevision and existing (add,
modify, remove)
- add/modify/remove child movements to match prevision
"""
add_list, modify_dict, \
delete_list = self._getCompensatedMovementList(applied_rule,
matching_property_list=['resource', 'source',
'destination','destination_total_asset_price',
'source_total_asset_price'],**kw)
if len(add_list) or len(modify_dict):
pass#import pdb; pdb.set_trace()
for movement_id in delete_list:
applied_rule._delObject(movement_id)
for movement, prop_dict in modify_dict.items():
applied_rule[movement].edit(**prop_dict)
for movement_dict in add_list:
if 'id' in movement_dict.keys():
mvmt_id = applied_rule._get_id(movement_dict.pop('id'))
new_mvmt = applied_rule.newContent(id=mvmt_id,
portal_type=self.movement_type)
else:
new_mvmt = applied_rule.newContent(portal_type=self.movement_type)
new_mvmt.edit(**movement_dict)
#set asset_price on movement when resource is different from price
#currency of the source/destination section
currency = new_mvmt.getResourceValue()
if currency is not None:
currency_url = currency.getRelativeUrl()
dest_section = new_mvmt.getDestinationSectionValue()
if dest_section is not None:
dest_currency_url = dest_section.getProperty('price_currency', None)
else:
dest_currency_url = None
if dest_currency_url is not None \
and currency_url != dest_currency_url:
precision = dest_section.getPriceCurrencyValue() \
.getQuantityPrecision()
dest_exchange_ratio = currency.getPrice(context=new_mvmt.asContext(
categories=['price_currency/%s' % dest_currency_url,
'resource/%s' % currency_url],
start_date=new_mvmt.getStartDate()))
if dest_exchange_ratio is not None:
new_mvmt.edit(destination_total_asset_price=round(
(dest_exchange_ratio*
applied_rule.getParentValue().getTotalPrice()),precision))
source_section = new_mvmt.getSourceSectionValue()
if source_section is not None:
source_currency_url = source_section.getProperty(
'price_currency', None)
else:
source_currency_url = None
if source_currency_url is not None \
and currency_url != source_currency_url:
precision = source_section.getPriceCurrencyValue() \
.getQuantityPrecision()
source_exchange_ratio = currency.getPrice(context=new_mvmt\
.asContext(
categories=['price_currency/%s' % source_currency_url,
'resource/%s' % currency_url],
start_date=new_mvmt.getStartDate()))
if source_exchange_ratio is not None:
new_mvmt.setSourceTotalAssetPrice(round(
source_exchange_ratio*applied_rule.getParentValue().getTotalPrice(),
precision))
# Pass to base class
BPMRule.expand(self, applied_rule, force=force, **kw)
# Matrix related
security.declareProtected( Permissions.ModifyPortalContent,
'newCellContent' )
......
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