I'm trying to count plan_payment_number
in tree view when group_by
, but SUM by default in Odoo v8. I need only count plan_payment_number
.
This is what I have now:
And this is what I need:
I tried with count = "true"
. My code on the tree view:
<record id="view_plan_car_tree" model="ir.ui.view">
<field name="name">plan.car.tree</field>
<field name="model">plan.car</field>
<field name="arch" type="xml">
<tree colors="blue:state == 'draft';black:state ==
'done';gray:state == 'cancel'" string="Payments">
<field name="number"/>
<field name="plan_payment_number" />
<field name="date_to"/>
<field name="name"/>
<field name="state"/>
<field name="contract_id"/>
<field name="partner_id"/>
<field name="initial_quota"/>
<field name="capital_quota"/>
<field name="administrative_quota"/>
<field name="pay_type"/>
<field name="company_id" groups="base.group_multi_company"
widget="selection"/>
<field name="plan_run_id" invisible="1"/>
</tree>
</field>
</record>
My solution for this problem is:
class plan_car(models.Model):
_inherit = 'plan.car'
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None,
context=None, orderby=False, lazy=True):
res = super(plan_car, self).read_group(cr, uid, domain, fields, groupby,
offset, limit=limit, context=context, orderby=orderby, lazy=lazy)
if 'plan_payment_number' in fields:
for line in res:
if '__domain' in line:
lines = self.search(cr, uid, line['__domain'], context=context)
pending_value = 0
for current_account in self.browse(cr, uid, lines,
context=context):
pending_value += 1
line['plan_payment_number'] = pending_value
return res