In Odoo 13, when I duplicate a sale order which has invoices linked to it, the new sale order has no invoices linked to it, which is OK.
The problem is that in my case, there are a lot of third party apps installed in my database, and here, when I duplicate a sale order, the new one has the same invoices linked to it than the source one, which obviously is a wrong behavior.
I am trying to fix it. So first I checked even through the interface that the following fields have copy=False
:
invoice_lines
from the model sale.order.line
.sale_line_ids
from the model
account.move.line
.Both seem to be OK, with copy=False
. Why is this happening then? I've also modified the code to break the program if they are modified in create
or write
ORM methods of both models, but they aren't.
Any ideas of how can I locate the guilty code?
Finally I've found the problem: one of the multiple third party apps installed on the database adds a new Many2many field on sale.order
pointing to account.move
. This field has not copy=False
. It shouldn't affect to sale order invoices link, but it does because the app also overwrites de method _get_invoiced()
from sale.order
, to add the value of that M2M field to the original invoice_ids
. The combination of both actions is the problem.
I was able to fix it just adding a copy=False
to that third party app new field. The problem was also fixed if I commented the _get_invoiced()
overwrite, but I've chose the first option to preserve what that app does.
These are the reasons why checking sale.order
copy()
method or checking copy
attribute on original fields gave no clues.