Hi!
I want to add a calculated field in Partner class.
To do this, I've made a module with the code below.
I made it first without trying to called parent function from super python method.
But I had this error:
NameError. name '_get_invoice_partner' is not defined
And now I have called them with super method, I have this error:
TypeError: super(type, obj): obj must be an instance or subtype of type
Is someone could help me please?
from openerp.osv import osv
from openerp.osv import orm
from openerp.osv import fields
class Partner(osv.osv):
'''Partner'''
_inherit = 'res.partner'
def _get_invoice_partner(self, cr, uid, ids, context=None):
res = super(Partner, self)._get_invoice_partner(cr, uid, ids, context=context)
return res
def _get_partner_id(self, cr, uid, ids, context=None):
res = super(Partner, self)._get_partner_id(cr, uid, ids, context=context)
return res
def _get_last_mb_product(self, cr, uid, ids, name, args, context=None):
"""Return the last membership product buy by a user"""
name=name[0]
res ={}
member_line_obj = self.pool.get('membership.membership_line')
for partner in self.browse(cr, uid, ids, context=context):
partner_id = partner.id
line_id = member_line_obj.search(cr, uid, [
('partner', '=', partner_id),
('date_cancel', '=', False)
], limit=1, order='date_from', context=context)
if line_id:
res[partner.id] = {name: product_id}
product_id = member_line_obj.read(cr, uid, line_id[0], [name], context=context)[name][0]
return res
_columns = {
'membership_id': fields.function(
_get_last_mb_product, multi='membership_id',
string='Last membership product',
type='many2one',
obj='product.product',
store = {
'account.invoice': (_get_invoice_partner, ['state'], 10),
'membership.membership_line': (_get_partner_id, ['state'], 10, )
}, help="Last membership product"),
}
Partner()
L'Heureux-Cyclage, Ludovic CHEVALIER,
Your code seems to be fine
One of the only reason seeming possible is because there is no '_get_invoice_partner' function in the main/super res.partner object, thats why it is showing error while executing that line.
Try keeping a print statement in "_get_invoice_partner" function, before calling super of it, if it executes that print statement then simply remove the super call and it should work
Hope it helps!
Hi Pawan! Thanks for your answer. "_get_invoice_partner" function existing in Partner class in pos_membership module. I put a print statement in pos_membership "_get_invoice_partner" function and in custom module. The one of pos_membership is called before the one of custom module. If I remove the super call in my custom module, I can't define a value to res and I have this logical error: NameError: global name 'res' is not defined And if I remove the return of res variable, I have this other logical error: TypeError: 'NoneType' object is not iterable :-(
you can try to use another methods that no exist in core odoo, for example you can use _get_partner_id_custom and _get_invoice_partner_custom and call inside new methods custom the original methods and after modify "res"