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 @@
import random
import zope.interface
from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
from Acquisition import aq_base, Implicit
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5Type import Permissions, interfaces
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
......@@ -55,8 +55,14 @@ class BaseAmountDict(Implicit):
self._cache = cache
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):
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):
for amount in movement_list:
......@@ -87,9 +93,9 @@ class BaseAmountDict(Implicit):
return self._dict[variated_base_amount]
except KeyError:
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:
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(
*variated_base_amount)
self._dict[variated_base_amount] = value
......@@ -120,12 +126,12 @@ class BaseAmountDict(Implicit):
try:
method = self._cache[base_amount]
except KeyError:
method = self._amount_generator_line._getTypeBasedMethod(
method = self.aq_base._amount_generator_line._getTypeBasedMethod(
'getBaseAmountQuantityMethod')
if method is not None:
method = method(base_amount)
if method is None:
method = self._amount_generator_line.getBaseAmountQuantity
method = self.aq_base._amount_generator_line.getBaseAmountQuantity
self._cache[base_amount] = method
if variation_category_list:
kw = dict(self._method_kw,
......
......@@ -96,9 +96,10 @@ class TestPayrollMixin(TestTradeModelLineMixin, ERP5ReportTestCase):
def getBaseAmountQuantity(delivery_amount, base_application,
variation_category_list=(), **kw):
if variation_category_list:
model = delivery_amount.getAmountGeneratorLine().getParentValue()
for variation in variation_category_list:
if variation.startswith('salary_range'):
cell = delivery_amount.getSpecialiseValue().getCell(variation)
if variation.startswith('salary_range/'):
cell = model.getCell(variation)
if cell is not None:
model_slice_min = cell.getQuantityRangeMin()
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