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