Commit 11077f97 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_invoicing: fix asset price value on movement

parent f363ac65
...@@ -124,12 +124,16 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -124,12 +124,16 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
.getParentValue().getParentValue() .getParentValue().getParentValue()
kw = {'delivery': None, 'resource': resource, 'price': 1} kw = {'delivery': None, 'resource': resource, 'price': 1}
return kw
if resource is not None: def getGeneratedMovementList(self, movement_list=None, rounding=False):
#set asset_price on movement when resource is different from price movement_list = super(InvoiceTransactionRuleMovementGenerator, self).getGeneratedMovementList(movement_list=movement_list, rounding=rounding)
#currency of the source/destination section portal = self._applied_rule.getPortalObject()
for arrow in 'destination', 'source': for arrow in 'destination', 'source':
section = input_movement.getDefaultAcquiredValue(arrow + '_section') for movement in movement_list:
resource = movement.getResource()
if resource is not None:
section = movement.getDefaultAcquiredValue(arrow + '_section')
if section is not None: if section is not None:
try: try:
currency_url = section.getPriceCurrency() currency_url = section.getPriceCurrency()
...@@ -138,15 +142,17 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -138,15 +142,17 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
if currency_url not in (None, resource): if currency_url not in (None, resource):
currency = portal.unrestrictedTraverse(currency_url) currency = portal.unrestrictedTraverse(currency_url)
exchange_ratio = currency.getPrice( exchange_ratio = currency.getPrice(
context=input_movement.asContext( context=movement.asContext(
categories=('price_currency/' + currency_url, categories=('price_currency/' + currency_url,
'resource/' + resource))) 'resource/' + resource)))
if exchange_ratio is not None: if exchange_ratio is not None:
kw[arrow + '_total_asset_price'] = round( if arrow == 'destination':
exchange_ratio * input_movement.getQuantity(), sign = 1
currency.getQuantityPrecision()) else:
sign = -1
movement.setProperty(arrow + '_total_asset_price', movement.getQuantity() * exchange_ratio * sign)
return kw return movement_list
def _getInputMovementList(self, movement_list=None, rounding=False): def _getInputMovementList(self, movement_list=None, rounding=False):
simulation_movement = self._applied_rule.getParentValue() simulation_movement = self._applied_rule.getParentValue()
......
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