This question has been flagged
1 Reply
2541 Views

Hi,

I am overriding _prepare_invoice in a custom module to copy the value of a sale order field to an invoice one.

But it doesn't work.

This is my code:

class XOrder(models.Model):

    _inherit = 'sale.order'

    payment_method = fields.Selection([

        ('transfer', 'Transfer'),

        ('credit_card', 'Credit Card'),

        ('check', 'Check'),

        ('cash', 'Cash')

    ])

    @api.v7

    def _prepare_invoice(self, cr, uid, order, lines, context=None):

        res = super(XOrder, self)._prepare_invoice(cr, uid, order, lines, context=context)

        res.update({'payment_method' : order.payment_method})

        return res    

class XInvoice(models.Model):

    _inherit = 'account.invoice'

    payment_method = fields.Selection([

        ('transfer', 'Transfer'),

        ('credit_card', 'Credit Card'),

        ('check', 'Check'),

        ('cash', 'Cash')

    ])


Could someone help ?

Avatar
Discard
Author

If I also override _make_invoice it works but I don't know if it is the right way.

Just remove this line:

@api.v7
Author Best Answer

I was completely wrong, such a newbie I am. I was using some sale order who was transformed to a stock picking form. It was normal that my field wasn't transmitted. If I make a new sale order and transform it to an Invoice, it wokrs as expected


Avatar
Discard