Skip to Content
Menu
This question has been flagged
2 Replies
2414 Views

Hi,

I want to add a many2many fields in my invoice! but when i use _prepare_invoice method i got an empty fields in my invoice view and no records in x_fleet_vehicle_invoice_rel table! so hope someone can help me with this...

class SaleOrderInherited(models.Model): 
    _inherit = 'sale.order' 
    order_field = fields.Many2many('fleet.vehicle', 'x_fleet_vehicle_sale_order_rel', 'order_id', 'vehicle_id', string='Order Field ') 
    @api.multi 
    def _prepare_invoice(self): 
        res = super(SaleOrder, self)._prepare_invoice() 
        res['invoice_field'] = self.order_field 
        return res 

class AccountInvoiceInherited(models.Model): 
    _inherit = 'account.invoice' 
    invoice_field = fields.Many2many('fleet.vehicle', 'x_fleet_vehicle_invoice_rel', 'invoice_id', 'vehicle_id', string='Invoice Field')
Avatar
Discard
Author Best Answer

Or just...

res['invoice_field'] = [(6, 0, self.order_field.ids)]
Avatar
Discard
Best Answer

Hi Lisa,

It will work, change your _prepare_invoice like below,

@api.multi
    def _prepare_invoice(self):
        res = super(SaleOrderInherited, self)._prepare_invoice()
        invoice_fields = []
        for d in self.order_field:
            invoice_fields.append(d.id)
        res['invoice_field'] = [(6, 0, invoice_fields)]
        return res

Avatar
Discard