Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits: 3bcca40c by Cédric Krier at 2023-02-12T22:59:37+01:00 Reset sale state to draft before adding or deleting extra lines Closes #12082 - - - - - b7f6e692 by Cédric Krier at 2023-02-12T23:03:15+01:00 Use same design to set extra than to set shipment cost - - - - - 1 changed file: - modules/sale_extra/sale.py Changes: ===================================== modules/sale_extra/sale.py ===================================== @@ -26,5 +26,8 @@ super(Sale, cls).quote(sales) - lines_to_delete = [] + # State must be draft to add or delete lines + # because extra must be set after to have correct amount + cls.write(sales, {'state': 'draft'}) + removed = [] for sale in sales: @@ -30,6 +33,5 @@ for sale in sales: - sale.set_extra(lines_to_delete) - if lines_to_delete: - Line.delete(lines_to_delete) + removed.extend(sale.set_extra()) + Line.delete(removed) cls.save(sales) @@ -34,6 +36,6 @@ cls.save(sales) - def set_extra(self, lines_to_delete): + def set_extra(self): 'Set extra lines and fill lines_to_delete' pool = Pool() Extra = pool.get('sale.extra') @@ -37,7 +39,7 @@ 'Set extra lines and fill lines_to_delete' pool = Pool() Extra = pool.get('sale.extra') - + removed = [] extra_lines = Extra.get_lines(self) extra2lines = {line.extra: line for line in extra_lines} lines = list(self.lines) @@ -49,7 +51,7 @@ continue else: lines.remove(line) - lines_to_delete.append(line) + removed.append(line) if extra2lines: lines.extend(extra2lines.values()) self.lines = lines @@ -53,6 +55,7 @@ if extra2lines: lines.extend(extra2lines.values()) self.lines = lines + return removed class Line(metaclass=PoolMeta): View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/compare/1178140d7803946cbf5a00e809839f344e2c0257...b7f6e692b04b213e88b998a418507c1afacaefd9 -- View it on Heptapod: https://foss.heptapod.net/tryton/tryton/-/compare/1178140d7803946cbf5a00e809839f344e2c0257...b7f6e692b04b213e88b998a418507c1afacaefd9 You're receiving this email because of your account on foss.heptapod.net.