Commit 6291d0f6 authored by Julien Muchembled's avatar Julien Muchembled

New method to get the current amount generator line from custom base_amount script

parent 103aa8b3
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
import random import random
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import Implicit from Acquisition import aq_base, Implicit
from Products.ERP5.AggregatedAmountList import AggregatedAmountList from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type import Permissions, interfaces from Products.ERP5Type import Permissions, interfaces
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
...@@ -55,8 +55,14 @@ class BaseAmountDict(Implicit): ...@@ -55,8 +55,14 @@ class BaseAmountDict(Implicit):
self._cache = cache self._cache = cache
self._method_kw = method_kw self._method_kw = method_kw
getAmountGeneratorLine__roles__ = None # public
def getAmountGeneratorLine(self):
# Use aq_base to avoid additional wrapping.
return aq_base(self)._amount_generator_line
def setAmountGeneratorLine(self, amount_generator_line): def setAmountGeneratorLine(self, amount_generator_line):
self._amount_generator_line = amount_generator_line # Use aq_base to keep acquisition context.
self.aq_base._amount_generator_line = amount_generator_line
def recurseMovementList(self, movement_list): def recurseMovementList(self, movement_list):
for amount in movement_list: for amount in movement_list:
...@@ -87,9 +93,9 @@ class BaseAmountDict(Implicit): ...@@ -87,9 +93,9 @@ class BaseAmountDict(Implicit):
return self._dict[variated_base_amount] return self._dict[variated_base_amount]
except KeyError: except KeyError:
value = 0 value = 0
amount_generator_line = self._amount_generator_line amount_generator_line = self.aq_base._amount_generator_line
for base_amount_dict in self._amount_list: for base_amount_dict in self._amount_list:
base_amount_dict._amount_generator_line = amount_generator_line base_amount_dict.aq_base._amount_generator_line = amount_generator_line
value += base_amount_dict.getGeneratedAmountQuantity( value += base_amount_dict.getGeneratedAmountQuantity(
*variated_base_amount) *variated_base_amount)
self._dict[variated_base_amount] = value self._dict[variated_base_amount] = value
...@@ -120,12 +126,12 @@ class BaseAmountDict(Implicit): ...@@ -120,12 +126,12 @@ class BaseAmountDict(Implicit):
try: try:
method = self._cache[base_amount] method = self._cache[base_amount]
except KeyError: except KeyError:
method = self._amount_generator_line._getTypeBasedMethod( method = self.aq_base._amount_generator_line._getTypeBasedMethod(
'getBaseAmountQuantityMethod') 'getBaseAmountQuantityMethod')
if method is not None: if method is not None:
method = method(base_amount) method = method(base_amount)
if method is None: if method is None:
method = self._amount_generator_line.getBaseAmountQuantity method = self.aq_base._amount_generator_line.getBaseAmountQuantity
self._cache[base_amount] = method self._cache[base_amount] = method
if variation_category_list: if variation_category_list:
kw = dict(self._method_kw, kw = dict(self._method_kw,
......
...@@ -96,9 +96,10 @@ class TestPayrollMixin(TestTradeModelLineMixin, ERP5ReportTestCase): ...@@ -96,9 +96,10 @@ class TestPayrollMixin(TestTradeModelLineMixin, ERP5ReportTestCase):
def getBaseAmountQuantity(delivery_amount, base_application, def getBaseAmountQuantity(delivery_amount, base_application,
variation_category_list=(), **kw): variation_category_list=(), **kw):
if variation_category_list: if variation_category_list:
model = delivery_amount.getAmountGeneratorLine().getParentValue()
for variation in variation_category_list: for variation in variation_category_list:
if variation.startswith('salary_range'): if variation.startswith('salary_range/'):
cell = delivery_amount.getSpecialiseValue().getCell(variation) cell = model.getCell(variation)
if cell is not None: if cell is not None:
model_slice_min = cell.getQuantityRangeMin() model_slice_min = cell.getQuantityRangeMin()
model_slice_max = cell.getQuantityRangeMax() model_slice_max = cell.getQuantityRangeMax()
......
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