Commit 424edbc3 authored by Łukasz Nowak's avatar Łukasz Nowak

- avoid code repetition

 - avoid code repetition
 - as category list are used use IndexError exception to know if category is set


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28247 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d164eddb
...@@ -60,6 +60,30 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -60,6 +60,30 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
, PropertySheet.AppliedRule , PropertySheet.AppliedRule
) )
def _getCurrencyRatioByArrow(self, arrow, prevision_line):
from Products.ERP5Type.Document import newTempSimulationMovement
temporary_movement = newTempSimulationMovement(self.getPortalObject(),
'1', **prevision_line)
exchange_ratio = None
try:
section = prevision_line['%s_list' % arrow][0]
except IndexError:
section = None
if section is not None:
currency_url = self.restrictedTraverse(section).getProperty(
'price_currency', None)
else:
currency_url = None
if currency_url is not None and self.getResource() != currency_url:
precision = section.getPriceCurrencyValue() \
.getQuantityPrecision()
exchange_ratio = currency.getPrice(
context=temporary_movement.asContext(
categories=['price_currency/%s' % currency_url,
'resource/%s' % self.getResource()],
start_date=temporary_movement.getStartDate()))
return exchange_ratio
#### Helper method for expand #### Helper method for expand
def _generatePrevisionList(self, applied_rule, **kw): def _generatePrevisionList(self, applied_rule, **kw):
""" """
...@@ -136,53 +160,22 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -136,53 +160,22 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
resource_list = [resource], resource_list = [resource],
price = 1, price = 1,
) )
from Products.ERP5Type.Document import newTempSimulationMovement
temporary_movement = newTempSimulationMovement(self.getPortalObject(),
'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: if resource is not None:
currency = self.restrictedTraverse(resource) #set asset_price on movement when resource is different from price
currency_url = currency.getRelativeUrl() #currency of the source/destination section
destination_section = prevision_line['destination_section_list'][0] destination_exchange_ratio = self._getCurrencyRatioByArrow(
if destination_section is not None: 'destination_section', prevision_line)
destination_currency_url = self.restrictedTraverse( if destination_exchange_ratio is not None:
destination_section).getProperty('price_currency', None) prevision_line.update(destination_total_asset_price=round(
else: (destination_exchange_ratio*
destination_currency_url = None applied_rule.getParentValue().getTotalPrice()),precision))
if destination_currency_url is not None \
and currency_url != destination_currency_url: source_exchange_ratio = self._getCurrencyRatioByArrow(
precision = destination_section.getPriceCurrencyValue() \ 'source_section', prevision_line)
.getQuantityPrecision() if source_exchange_ratio is not None:
destination_exchange_ratio = currency.getPrice( prevision_line.update(source_total_asset_price=round(
context=temporary_movement.asContext( (source_exchange_ratio*
categories=['price_currency/%s' % destination_currency_url, applied_rule.getParentValue().getTotalPrice()),precision))
'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_list'][0]
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( if accounting_rule_cell_line.hasProperty(
'generate_prevision_script_id'): 'generate_prevision_script_id'):
......
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