Skip to content
Snippets Groups Projects
Commit 84cb3b9c authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[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#41915

Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 76a0e4fe
Branches
Tags
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment