Hello everyone,
I want to fill invoice_line based on invoice_id, I have created a change function but I'm getting an error could you help me please.
This is my 2 functions:
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
res = super(kms_invoice, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
if partner_id:
invoice_id = self.env['account.invoice'].search([('partner_id', '=', partner_id)])
p = self.env['res.partner'].browse(partner_id)
print 'invoice_id',invoice_id
res = {'value':{'user_id': p.user_id},'domain':{'invoice_id':[('partner_id','=',partner_id)]}}
return res
@api.multi
def onchange_invoice_id(self, invoice_id, partner_id, context=None):
res={}
vals=0
if invoice_id:
invoice_line_ids = self.env['account.invoice.line'].search( [('invoice_id', '=', invoice_id)])
# p = self.env['account.invoice.line'].browse(invoice_id)
print 'invoice_line_ids',invoice_line_ids
r=[]
for line in invoice_line_ids:
r.append({
'product_id':line.product_id,
'name': line.name,
'company_id':line.company_id,
'account_id':line.account_id,
'account_analytic_id':line.account_analytic_id,
'quantity':line.quantity,
'uos_id':line.uos_id,
'price_unit':line.price_unit,
'discount':line.discount,
'invoice_line_tax_id':line.invoice_line_tax_id,
'price_subtotal':line.price_subtotal
})
res =vals.update({'invoice_line':r})
return res