Skip to Content
Menu
This question has been flagged
1 Reply
2848 Views

Hello everyone,

In the invoice I had added a field the invoice number and depending on this field the refund invoice line will be filled the pb is when I save those line are deleted.

This is my code:

'invoice_id' : fields.many2one('account.invoice', string='Invoice number'),

def onchange_invoice_id(self, cr, uid, ids, invoice_id, context=None):

obj_inv_line = self.pool.get('account.invoice.line')

acc_line_ids = []

if invoice_id:

acc_line_ids = obj_inv_line.search(cr, uid, [('invoice_id', '=', invoice_id)])

return {'value': {'invoice_line': acc_line_ids}}

Any help please???

Avatar
Discard
Best Answer

Hi

you must overwrite create and write function, then you must  call this onchange function  and update vals dictionary values before the return like this:

def create(self, cr, uid, vals, context=None):

    res= {}

    res= self.onchange_invoice_id(cr, uid, [],vals.get('invoice_id',False), context=context)

    vals.update(res.get('value',{}))

    return super(your_class_name, self).create(cr, uid, vals, context=context)

Avatar
Discard
Author

Hello, thanks for your answer but could you explain more