Hi guys,
I'm building a module that copies a whole invoice from one database to another the moment the user clicks on a button. I have a working concept, as long as there is one line (one product) on the invoice.
The code:
# Get all ids from all taxes in the current database tax_ids = [] for tax_id in self.invoice_line.invoice_line_tax_id: result = tax_proxy.search([('name', '=', tax_id.name)]) # This means the tax doesn't exist in the target db if not result: # Create tax in target database. new_tax_id = tax_proxy.create({ 'name': tax_id.name, 'amount': tax_id.amount, 'price_include': tax_id.price_include, 'include_base_amount': tax_id.include_base_amount, 'child_depend': tax_id.child_depend }) tax_ids.append(new_tax_id.id) else: tax_ids.append(tax_id.id) # Create the 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, 'fiscal_position': self.fiscal_position, 'payment_term': self.payment_term, 'comment': self.comment, 'type': 'in_invoice', 'invoice_line': [(0, 0, { 'name': self.invoice_line.name, 'product_id': self.invoice_line.product_id.id, 'account_id': self.invoice_line.account_id.id, 'invoice_line_tax_id': [(6, 0, tax_ids)], 'quantity': self.invoice_line.quantity, 'price_unit': self.invoice_line.price_unit })] })
This however leaves me with two problems that I am unsure on how to solve:
1) The taxes are all added to a list before I do invoice_proxy.create, to create the invoice. This means that all taxes from all products will be applied. The reason that I did this before invoice_proxy.create was exactly for the same issue as problem #2.
2) This code will work if there is an invoice with one product line, but not with multiple (otherwise you'll get a singleton error).
So what I'm wondering is how should I exactly create multiple invoice_lines (with the correct taxes filled in in the many2many invoice_line_tax_id) in this .create function?
Regards,
Yenthe