i am doing migration to odoo 15 and i am uploading the Sales order and invoices separately
so in there is any way to link sales order to the invoice after i uploading them ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Hi,
If you are familiar with code you can try the following.
In the sale order, we have a many2many field named invoice_ids. The invoice corresponding to the sale order is linked there.
So you can create a one-time running code and by searching the corresponding invoice id and you can Update that to the sale order record
def update_invocie_ids(self):
sale_ids = self.env['sale.order'].search([])
for sale_id in sale_ids:
inovice_id = self.env['account.move'].search(["YOUR CONDITION TO MATCH THE RECORD"])
sale_id.write{(
'invoice_ids': [(4, "YOUR INVOICE IDS")],
)}
Regards
Correct way to do this is if the sale order and the invoice has just one line that match is :
# Assume you already have the sale order and invoice records
so = self.env['sale.order'].browse(SALE_ORDER_ID)
inv = self.env['account.move'].browse(INVOICE_ID)
# 1. Link invoice to sale order
inv.invoice_origin = so.name
# 2. Get the only line from each
so_line = so.order_line[0]
inv_line = inv.invoice_line_ids[0]
# 3. Link invoice line to sale order line
inv_line.sale_line_ids = [(6, 0, [so_line.id])]
# 4. Optional: Set analytic account if needed
if so.analytic_account_id:
inv_line.analytic_account_id = so.analytic_account_id.id
# 5. Optional: Link invoice back to sale order (inverse)
so.invoice_ids = [(4, inv.id)]
inv.message_post(body=f"Linked manually to SO <b>{so.name}</b>")
so.message_post(body=f"Linked manually to Invoice <b>{inv.name}</b>")
You cannot edit the invoice_ids field because it is a computed field.
It updates the order lines with the corresponding invoice lines.
it ensures that the invoices are correctly related to the sales
This is a very good question! actualy I have same problem... @julien did you find a way?
What I found in other posts is the following:
Hi,
If you create sale order and the invoice, Then to link the invoice with the sales, you can add the id's of the invoices you have created to the field name invoice_ids in sale.order model. This is a many2many field.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
Hello Ahmed,
Any answer ?
Thanks
Hello Julien
unfortunately i got no answer
and for now i still don't have answer of this question
hello together, did you found a solution for linking a invoice to an existing SO?
thx, michael