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

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

By
Alan Luo
on 7/27/15, 10:32 PM 596 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

try:

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'))

except:

pass

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')

}


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: 7/27/15, 10:32 PM
Seen: 596 times
Last updated: 7/27/15, 10:32 PM