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,98 +148,64 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -148,98 +148,64 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
context_movement.getPrice(0.0)) * context_movement.getPrice(0.0)) *
accounting_rule_cell_line.getQuantity(), accounting_rule_cell_line.getQuantity(),
'price': 1, 'price': 1,
'force_update': 1,
'causality_value': business_path, 'causality_value': business_path,
} }
from Products.ERP5Type.Document import newTempSimulationMovement
if accounting_rule_cell_line.hasProperty( temporary_movement = newTempSimulationMovement(self.getPortalObjec(),
'generate_prevision_script_id'): '1', **prevision_line)
generate_prevision_script_id = \
accounting_rule_cell_line.getGeneratePrevisionScriptId()
prevision_line.update(getattr(context_movement,
generate_prevision_script_id)(prevision_line))
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 #set asset_price on movement when resource is different from price
#currency of the source/destination section #currency of the source/destination section
currency = new_mvmt.getResourceValue() if resource is not None:
if currency is not None: currency = self.restrictedTraverse(resource)
currency_url = currency.getRelativeUrl() currency_url = currency.getRelativeUrl()
dest_section = new_mvmt.getDestinationSectionValue() destination_section = prevision_line['destination_section']
if dest_section is not None: if destination_section is not None:
dest_currency_url = dest_section.getProperty('price_currency', None) destination_currency_url = self.restrictedTraverse(
destination_section).getProperty('price_currency', None)
else: else:
dest_currency_url = None destination_currency_url = None
if dest_currency_url is not None \ if destination_currency_url is not None \
and currency_url != dest_currency_url: and currency_url != destination_currency_url:
precision = dest_section.getPriceCurrencyValue() \ precision = destination_section.getPriceCurrencyValue() \
.getQuantityPrecision() .getQuantityPrecision()
dest_exchange_ratio = currency.getPrice(context=new_mvmt.asContext( destination_exchange_ratio = currency.getPrice(
categories=['price_currency/%s' % dest_currency_url, context=temporary_movement.asContext(
categories=['price_currency/%s' % destination_currency_url,
'resource/%s' % currency_url], 'resource/%s' % currency_url],
start_date=new_mvmt.getStartDate())) start_date=temporary_movement.getStartDate()))
if dest_exchange_ratio is not None: if destination_exchange_ratio is not None:
new_mvmt.edit(destination_total_asset_price=round( prevision_line.update(destination_total_asset_price=round(
(dest_exchange_ratio* (destination_exchange_ratio*
applied_rule.getParentValue().getTotalPrice()),precision)) applied_rule.getParentValue().getTotalPrice()),precision))
source_section = new_mvmt.getSourceSectionValue() source_section = prevision_line['source_section']
if source_section is not None: if source_section is not None:
source_currency_url = source_section.getProperty( source_currency_url = self.restrictedTraverse(
'price_currency', None) 'source_section').getProperty('price_currency', None)
else: else:
source_currency_url = None source_currency_url = None
if source_currency_url is not None \ if source_currency_url is not None \
and currency_url != source_currency_url: and currency_url != source_currency_url:
precision = source_section.getPriceCurrencyValue() \ precision = source_section.getPriceCurrencyValue() \
.getQuantityPrecision() .getQuantityPrecision()
source_exchange_ratio = currency.getPrice(context=new_mvmt\ source_exchange_ratio = currency.getPrice(
.asContext( context=temporary_movement.asContext(
categories=['price_currency/%s' % source_currency_url, categories=['price_currency/%s' % source_currency_url,
'resource/%s' % currency_url], 'resource/%s' % currency_url],
start_date=new_mvmt.getStartDate())) start_date=temporary_movement.getStartDate()))
if source_exchange_ratio is not None: if source_exchange_ratio is not None:
new_mvmt.setSourceTotalAssetPrice(round( prevision_line.update(source_total_asset_price = round(
source_exchange_ratio*applied_rule.getParentValue().getTotalPrice(), source_exchange_ratio*applied_rule.getParentValue().getTotalPrice(),
precision)) precision))
# Pass to base class if accounting_rule_cell_line.hasProperty(
BPMRule.expand(self, applied_rule, force=force, **kw) 'generate_prevision_script_id'):
generate_prevision_script_id = \
accounting_rule_cell_line.getGeneratePrevisionScriptId()
prevision_line.update(getattr(context_movement,
generate_prevision_script_id)(prevision_line))
prevision_list.append(prevision_line)
return prevision_list
# Matrix related # Matrix related
security.declareProtected( Permissions.ModifyPortalContent, security.declareProtected( Permissions.ModifyPortalContent,
......
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