Skip to Content
Menu
This question has been flagged
3 Replies
4488 Views

hi

I want add a function in customer payment form that when I select a partner, a field withe name 'section_id' be automatically selected.

for this I add a field with name 'section_id'(many2one) with relation crm_case_section table.

and in account_voucher module, I add this code in onchange_partner_id function:

------------------------------------------------

    def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date,section_id, context=None):

        section_id = False

        if not journal_id:

            return {}

        res = self.recompute_voucher_lines(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)

        vals = self.recompute_payment_rate(cr, uid, ids, res, currency_id, date, ttype, journal_id, amount, context=context)

        for key in vals.keys():

            res[key].update(vals[key])

        return res

        if partner_id:

            partner = self.pool.get('res.partner').browse(cr, uid, partner_id)

                    value['section_id'] = partner.section_id.name

        return {'value': value}
---------------------------------------------------------------

but when I select a partner, 'section_id' field does not select. I don't know what is problem?


Thanks

Avatar
Discard

you had taken partner.section_id.name so that not working please use this one: partner.section_id and partner.section_id.id or False or you can use code from my answer.

Best Answer

use the decorator @api.constraints of the api v8

Avatar
Discard
Best Answer

call the super method instead of overriding the existing one see below code:

   

 def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=None):
     res = super(account_voucher, self).onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)
     if not partner_id:
        return res
     partner = self.pool.get('res.partner').browse(cr, uid, partner_id) 
     res['value'].update({'section_id': partner.section_id and partner.section_id.id or False})
     return res

where account_voucher: is the class name in super calling

           

Avatar
Discard