Help

3

how to pass default values to account.invoice.lines in context?

Avatar
Muhammad Anees

Hii,

From a custom module I am passing the following default values to account.invoice when clicking create button.
Custom Field Id
Vendor
Journal

Following is the code how I passing default values in the context and it set default values successfully to account.invoice.

@api.multi
def show_insurance_invoices(self):
return {
'name': _('Insurance Bills'),
'domain': [('shipment_id', '=', self.id), ('journal_id', '=', self.insurance_journal_id.id)],
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.invoice',
'view_id': False,
'type': 'ir.actions.act_window',
'context': {
'default_shipment_id': self.id,
'default_journal_id': self.insurance_journal_id.id,
'default_partner_id': self.insurance_partner_id.id
},
}

Is there a way to pass default product id or some other values in the above context and line auto created and values assigned on account.invoice.line model?

1 Comment
Avatar
Discard
Avatar
Sehrish
-
1 Answer
3
Avatar
Muhammad Anees
Best Answer

I solved it the different way. 

Instead of passing the default values from my custom module to account.invoice.
I created new button in my custom module called Create Insurance Bill.
In this method I created new invoice object and passed all header and lines info. Job beautifully done.

Here is the code..

@api.multi
    def create_insurance_bill(self):
result = self.env['account.invoice'].create({ 'partner_id': self.insurance_partner_id.id, 'shipment_id': self.id, 'name': 'Insurance Bill', 'type': 'in_invoice', 'origin': self.name, 'journal_id': self.insurance_journal_id.id,
'invoice_line_ids': [(0, 0, {
'name': self.insurance_product_id.name,
'origin': self.name,
'account_id': self.insurance_product_id.property_account_expense_id.id,
'price_unit': self.insurance_amount,
'quantity': 1.0,
'discount': 0.0,
'uom_id': self.insurance_product_id.uom_id.id,
'product_id': self.insurance_product_id.id,
})],
})
Avatar
Discard