From 4e60d28d00550235e0a4091a769f68f8cb51051c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 14 Dec 2016 13:12:39 +0100 Subject: [PATCH] =?UTF-8?q?[FIX]project=5Ftimesheet,=20sale:=C2=A0SO=20lin?= =?UTF-8?q?e=20not=20updated=20after=20timesheet=20is=20deleted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Deleting some timesheets linked to a task created on a SO didn't update the delivred quantity. opw:697317 --- addons/sale/sale_analytic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/sale/sale_analytic.py b/addons/sale/sale_analytic.py index e3b5fdcb440..4b20d388c3e 100644 --- a/addons/sale/sale_analytic.py +++ b/addons/sale/sale_analytic.py @@ -18,6 +18,11 @@ class SaleOrderLine(models.Model): domain, ['so_line', 'unit_amount', 'product_uom_id'], ['product_uom_id', 'so_line'], lazy=False ) + # If the unlinked analytic line was the last one on the SO line, the qty was not updated. + force_so_lines = self.env.context.get("force_so_lines") + if force_so_lines: + for line in force_so_lines: + lines.setdefault(line, 0.0) for d in data: if not d['product_uom_id']: continue @@ -124,3 +129,10 @@ class AccountAnalyticLine(models.Model): line.with_context(create=True).write(res) line.mapped('so_line').sudo()._compute_analytic() return line + + @api.multi + def unlink(self): + so_lines = self.mapped('so_line') + res = super(AccountAnalyticLine, self).unlink() + so_lines.with_context(force_so_lines=so_lines).sudo()._compute_analytic() + return res