This question has been flagged
1 Reply
3951 Views

Hii,

I have a custom field added in the header of the account.invoice. I have added the same custom filed to account.invoice.line.
When I create an Invoice directly or from PO I assign a value to this field.
How to pass custom field value to from invoice header to all lines?

I have done it  overriding write() and onchage() methods but no luck on create() method. 

How to pass it by overriding create() method.

I am doing it the following way but not working...

@api.model
def create(self, values):
result = super(FFTAccountInvoice, self).create(values)
     values.update({'invoice_line_ids': [(0, 0, {'shipment_id': result['shipment_id'].id})]})
     return result



Avatar
Discard
Author Best Answer

The requirement can be achieved by overriding create() and write() methods, or even field onchage() method.
But I have done it by Related field as following and it is working fine with me..

class TTAccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'
    shipment_id = fields.Many2one('purchase.shipment', string='Shipment', related='invoice_id.shipment_id', store=True)

 in account.invoice i have custom filed shipment_id. So related='invoice_id.shipment_id'.

Avatar
Discard