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 ?.