changeset 98c3e3c4b7bf in modules/account_stock_landed_cost_weight:default
details: 
https://hg.tryton.org/modules/account_stock_landed_cost_weight?cmd=changeset&node=98c3e3c4b7bf
description:
        Store allocation factors

        issue10959
        review351051002
diffstat:

 CHANGELOG  |   2 ++
 account.py |  10 ++++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diffs (37 lines):

diff -r 774349f1b5b9 -r 98c3e3c4b7bf CHANGELOG
--- a/CHANGELOG Mon Dec 13 23:10:09 2021 +0100
+++ b/CHANGELOG Thu Dec 16 22:31:08 2021 +0100
@@ -1,3 +1,5 @@
+* Store allocation factors
+
 Version 6.2.0 - 2021-11-01
 * Bug fixes (see mercurial logs for details)
 
diff -r 774349f1b5b9 -r 98c3e3c4b7bf account.py
--- a/account.py        Mon Dec 13 23:10:09 2021 +0100
+++ b/account.py        Thu Dec 16 22:31:08 2021 +0100
@@ -14,10 +14,12 @@
         cls.allocation_method.selection.append(('weight', 'By Weight'))
 
     def allocate_cost_by_weight(self):
-        self._allocate_cost(self._get_weight_factors())
+        self.factors = self._get_weight_factors()
+        self._allocate_cost(self.factors)
 
     def unallocate_cost_by_weight(self):
-        self._allocate_cost(self._get_weight_factors(), sign=-1)
+        factors = self.factors or self._get_weight_factors()
+        self._allocate_cost(factors, sign=-1)
 
     def _get_weight_factors(self):
         "Return the factor for each move based on weight"
@@ -32,7 +34,7 @@
         length = Decimal(len(moves))
         for move in moves:
             if not sum_weight:
-                factors[move.id] = 1 / length
+                factors[str(move.id)] = 1 / length
             else:
-                factors[move.id] = weights[move.id] / sum_weight
+                factors[str(move.id)] = weights[move.id] / sum_weight
         return factors

Reply via email to