From 640011cf71d707e2b1e55bb8cb71d0bfe9de1a1d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 16 Dec 2019 11:16:08 +0000 Subject: [PATCH] [FIX] stock_account: delete COGS when set to draft - Create a product A, FIFO & Automated - Create a SO, deliver and invoice - Post the invoice - Reset it to draft - Post the invoice again The COGS lines are duplicated. Unlike the other lines, the COGS lines are only added at posting. This is done in case several invoices are generated in draft, but validated in an arbitrary order. We clean up the COGS lines when resetting to draft. opw-2153695 opw-2152465 closes odoo/odoo#41931 X-original-commit: 84cb3b9c848ed42017b3253ca70b9455c8af7307 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_account/models/account_move.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 6c39f5f6034..36f7de46eba 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -38,11 +38,20 @@ class AccountMove(models.Model): self._stock_account_anglo_saxon_reconcile_valuation() return res + def button_draft(self): + res = super(AccountMove, self).button_draft() + + # Unlink the COGS lines generated during the 'post' method. + self.mapped('line_ids').filtered(lambda line: line.is_anglo_saxon_line).unlink() + return res + def button_cancel(self): # OVERRIDE res = super(AccountMove, self).button_cancel() # Unlink the COGS lines generated during the 'post' method. + # In most cases it shouldn't be necessary since they should be unlinked with 'button_draft'. + # However, since it can be called in RPC, better be safe. self.mapped('line_ids').filtered(lambda line: line.is_anglo_saxon_line).unlink() return res