Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9313 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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,
})],
})
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 22
2203
0
thg 3 15
3217
1
thg 11 19
8022
0
thg 3 18
4563
1
thg 3 24
2807