Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
9312 Visualizzazioni

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?

Avatar
Abbandona
Autore Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
feb 22
2203
0
mar 15
3217
1
nov 19
8022
0
mar 18
4563
1
mar 24
2807