Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Method Override : Super not working openerpv7

By
Yassine TEIMI
on 12/11/14, 5:36 AM 664 views

I overrided an onchange method : basic_onchange_partner of account_voucher ( Customer Payments view), wich displays the default accout_id of the selected partner, as follows :

from openerp.osv import fields, orm, osv

class AccountVoucher(orm.Model):

    _inherit = 'account.voucher'
    _name = 'account.voucher'
    _columns = {
        'bls_to_pay': fields.one2many('stock.picking.out','bl_id','BLS to pay'),
    }

   def basic_onchange_partner(self, cr, uid, ids, partner_id, journal_id, ttype, context=None):
        if context==None:
            context={ }
       # here is the call of super 

       super(AccountVoucher, self).basic_onchange_partner(cr,uid,ids, partner_id, journal_id, ttype, context)

      # end of super call
        DO = self.pool.get('stock.picking.out')
        default = {
            'value': {'bls_to_pay' : [] ,},
        }
        do2pay_ids = DO.search(cr, uid, [('partner_id','=',partner_id),('state','=','done'),('invoice_state','=','2binvoiced')])
        for do2pay in do2pay_ids :
            do_rec= DO.browse(cr, uid, do2pay)
            rs = {
                'num_bl': do_rec.num_bl,
                'date' : do_rec.date,
                'origin': do_rec.origin,
            }
            default['value']['bls_to_pay'].append(rs) 
        return default

All stuffs that I added are working, apart of displaying account_id of selected partner.

Knowing that the original method does this :

    def basic_onchange_partner(self, cr, uid, ids, partner_id, journal_id, ttype, context=None):
        partner_pool = self.pool.get('res.partner')
        journal_pool = self.pool.get('account.journal')
        res = {'value': {'account_id': False}}
        if not partner_id or not journal_id:
            return res

        journal = journal_pool.browse(cr, uid, journal_id, context=context)
        partner = partner_pool.browse(cr, uid, partner_id, context=context)
        account_id = False
        if journal.type in ('sale','sale_refund'):
            account_id = partner.property_account_receivable.id
        elif journal.type in ('purchase', 'purchase_refund','expense'):
            account_id = partner.property_account_payable.id
        else:
            account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id

        res['value']['account_id'] = account_id
        return res

 Is it about the return value ? what makes the original one not diplaying account_id field value ?.

 

 

1
Harsh Dhaduk
On 12/11/14, 7:21 AM

Hi Yassine,

you can check below code.

 

from openerp.osv import fields, orm, osv

class AccountVoucher(orm.Model):

    _inherit = 'account.voucher'
    _name = 'account.voucher'
    _columns = {
        'bls_to_pay': fields.one2many('stock.picking.out','bl_id','BLS to pay'),
    }

    def basic_onchange_partner(self, cr, uid, ids, partner_id, journal_id, ttype, context=None):
        if context==None:
            context={ }
            

        res = super(AccountVoucher, self).basic_onchange_partner(cr,uid,ids, partner_id, journal_id, ttype, context)

        
        DO = self.pool.get('stock.picking.out')
        res['value']['bls_to_pay'] = []
         
        do2pay_ids = DO.search(cr, uid, [('partner_id','=',partner_id),('state','=','done'),('invoice_state','=','2binvoiced')])
        for do2pay in do2pay_ids :
            do_rec= DO.browse(cr, uid, do2pay)
            rs = {
                'num_bl': do_rec.num_bl,
                'date' : do_rec.date,
                'origin': do_rec.origin,
            }
            res['value']['bls_to_pay'].append(rs)
        return res

 

Best,

Harsh Dhaduk

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 12/11/14, 5:46 AM

Yes, you need to take the super's return and incorporate whatever changes to that return value (or incorporate whatever in the return value to a new return value).

So you should do: super_res = super(AccountVoucher, self).basic_onchange_partner(cr,uid,ids, partner_id, journal_id, ttype, context)

And then before return, default['values'].update(super_res.get('values', {})). And do it for the other 2 keys for the return values: domain and warning.  You may need to set default[key] = {} if it is not initialized yet.

and if I want to add only one field, and not 2 and more to the original return, should I just do Like Harsh Dhaduk told ?

Yassine TEIMI
on 2/23/15, 9:31 AM

@Harsh Dhaduk's answer would work as it is using the return of super as the primary variable to return instead of creating a new variable (variable default in your code).

Ivan
on 2/24/15, 12:54 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/11/14, 5:36 AM
Seen: 664 times
Last updated: 3/16/15, 8:10 AM