Odoo Help

1

0
1 Answer
1
Avatar

Yenthe Van Ginneken

--Yenthe Van Ginneken--
22565
| 9 9 12
Turnhout, Belgio
--Yenthe Van Ginneken--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe Van Ginneken
22/04/16, 09:12

Hi guys,

I ended up doing invoice_proxy.create first without the orderlines, just the invoice template.
After I created the invoice I loop over every line in invoice_line and do invoice_proxy.write to write one product at a time on the invoice. The code to create the invoice:

# Create the invoice! new_invoice = invoice_proxy.create({ 'partner_id': partner_id, # This should be Mavi-Rent (res.contact company record) 'account_id': account[0], 'date_invoice': self.date_invoice, 'date_due': self.date_due, 'reference': self.reference, 'origin': self.origin, 'fiscal_position': self.fiscal_position, 'payment_term': self.payment_term, 'comment': self.comment, 'type': 'in_invoice'

})

Writing a invoice_line away at a time in a for loop:

for invoice_line in self.invoice_line: # Write a line on the before created invoice new_invoice.write({ 'invoice_line': [(0, 0, { 'name': invoice_line.name, 'product_id': product_id, 'account_id': invoice_line.account_id.id, 'invoice_line_tax_id': [(6, 0, tax_ids)], 'quantity': invoice_line.quantity, 'price_unit': invoice_line.price_unit })]

})


When doing these operations there are a few things to watch out for though. Some examples:

  • Products may exist on your current database, but not on the database you write to

  • Taxes may exist on your current database, but not on the database you write to

  • Customers may exist on your customer database, but not on the database you write to

  • Any record that does not exist on your target database should be created through XML-RPC in the target database. Be sure to take the ID from the record of the remote database, not the current database. You will otherwise try to reference products from your local database in the target database that do not exist there (or, even worse, link to another product)

I hope this helps somebody in the future.

Yenthe

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now