0

I run Flectra inside a Docker container. I have custom fields in sale.order which I want to transfer to account.invoice.

class SaleOrder(models.Model):
    _inherit = 'sale.order' 
    myField = fields.Integer(string='My Field', default=21, required = True)

    @api.multi
    def _prepare_invoice(self):
         res = super(SaleOrder, self)._prepare_invoice()
         # res.update({
         #     'myField': self.myField,
         # })
         res['myField'] = self.myField
         return res


class SaleInvoice(models.Model):
    _inherit = 'account.invoice' 
    myField = fields.Integer(string='My Field', default=21, required = True)

I tried to override _prepare_invoice and also _create_invoices in different variations, but none worked. From my understanding they should have worked, but I am new to Odoo/Flectra, so I would be happy for any help.

I use Flectra 1.7 (Community Edition) which I think corresponds to Odoo 14.

headkit
  • 3,307
  • 4
  • 53
  • 99

1 Answers1

1

Try this:

def create_invoice(self):
    for rec in self:
        invoice = rec.env['account.move'].create({
            'move_type': 'out_invoice',
            # 'partner_id': self.partner.id, 
            'journal_id': 18, # say u forget to create journal 
            # 'currency_id': self.env.ref('base.USD').id, 
            'payment_reference': 'invoice to client',  

            'invoice_line_ids': [(0, 0, {
                'product_id': self.env['product.product'].create({'name': 'A Test Product'}),
                'quantity': 1,
                'price_unit': 40,
                'name': 'Your project product',
            })],
        })
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Adrian Mole Sep 22 '21 at 15:40