[IMP] crm_partner_assign: added computed field counting the number
of references of a partner. This allows to order / filter / do whatever you want with the number of references.
This commit is contained in:
parent
9530ff9fb5
commit
93c4e0da57
|
@ -53,6 +53,22 @@ class res_partner_activation(osv.osv):
|
|||
|
||||
class res_partner(osv.osv):
|
||||
_inherit = "res.partner"
|
||||
|
||||
def _get_implemented_count(self, cr, uid, ids, field_name, arg, context):
|
||||
res = dict.fromkeys(ids, 0)
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
res[partner.id] = len(partner.implemented_partner_ids)
|
||||
return res
|
||||
|
||||
def _get_partner_from_implementation(self, cr, uid, ids, context=None):
|
||||
pids = set()
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
pids.add(partner.id)
|
||||
if partner.assigned_partner_id:
|
||||
pids.add(partner.assigned_partner_id.id)
|
||||
pids = pids | set([p.id for p in partner.implemented_partner_ids])
|
||||
return list(pids)
|
||||
|
||||
_columns = {
|
||||
'partner_weight': fields.integer('Grade Weight',
|
||||
help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"),
|
||||
|
@ -71,6 +87,11 @@ class res_partner(osv.osv):
|
|||
'res.partner', 'assigned_partner_id',
|
||||
string='Implementation References',
|
||||
),
|
||||
'implemented_count': fields.function(
|
||||
_get_implemented_count, string="Implementations", type='integer',
|
||||
store={
|
||||
'res.partner': (_get_partner_from_implementation, ['assigned_partner_id', 'implemented_partner_ids'], 10),
|
||||
}),
|
||||
}
|
||||
_defaults = {
|
||||
'partner_weight': lambda *args: 0
|
||||
|
|
|
@ -112,6 +112,7 @@
|
|||
<field name="grade_id" widget="selection"/>
|
||||
<field name="activation" widget="selection"/>
|
||||
<field name="partner_weight"/>
|
||||
<field name="assigned_partner_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<separator string="Partner Review" colspan="2"/>
|
||||
|
|
Loading…
Reference in New Issue