Skip to Content
Menu
This question has been flagged
2 Replies
3028 Zobrazenia

Is there any possibility to display a project count in the Customer Form View?

Thanks.

Avatar
Zrušiť
Best Answer

If you mean the number of projects related to a customer

class res_partner(osv.Model):

_name = 'res.partner'

_inherit = 'res.partner'

def _get_number_of_projects(self, cr, uid, ids, name, args, context=None):

res = {}

for partner_id in ids:

proj_ids = self.pool.get('project.project').search(cr, uid, [('partner_id', 'in', ids)], context=context)

res[partner_id] = len(proj_ids)

return res

 

_columns = {

'num_of_projects': fields.function(_get_number_of_projects, type='integer', string='Number Of Projects' , store=True),

}

Then in the view :

<record id="inherit_partner_veiw" model="ir.ui.view">

<field name="name">Inherit Partner View</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

<field name="arch" type="xml">

<xpath expr="//field[@name='website'] " position="after">

<field name="num_of_projects"/>

</xpath>

</field>

</record>

I Hope this helps you :)

Avatar
Zrušiť

I'm gradually learning Odoo through trial and error and community help. How or where do I implement this, do I have to build a module or can I add this to the existing code (if yes - what and where). Thanks for your support and time Chris Keen

Autor Best Answer

Hi Mohamed, 

thank's for your answer, 

i think it will works, will try!

Regards

 

Avatar
Zrušiť