Odoo Help


how to add contexted buttons into the res.partner form view

Alan Luo
on 7/27/15, 10:32 PM 1,258 views

I have added new filed successfulcdd into sale.order, now I want to add a buttons into res.partner form which locate on the top right.

'successfulcdd': fields.many2one('res.partner), 

The purpose is want to make all sales orders linked to a company and a person.

Following is original res_partner.py code, it's default count partner.id field in sale.order. How should I change the code to make bottom count successfulcdd as well?

from openerp.osv import fields,osv

class res_partner(osv.osv):

_inherit = 'res.partner'

def _sale_order_count(self, cr, uid, ids, field_name, arg, context=None):

res = dict(map(lambda x: (x,0), ids))

# The current user may not have access rights for sale orders


for partner in self.browse(cr, uid, ids, context):

res[partner.id] = len(partner.sale_order_ids) + len(partner.mapped('child_ids.sale_order_ids'))



return res

_columns = {

'sale_order_count': fields.function(_sale_order_count, string='# of Sales Order', type='integer'),

'sale_order_ids': fields.one2many('sale.order','partner_id','Sales Order')


About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/27/15, 10:32 PM
Seen: 1258 times
Last updated: 7/27/15, 10:32 PM