Files
odoo_source/addons/project/models/res_partner.py
T
Goffin Simon c555cdca62 [FIX] point_of_sale, project: Smart buttons to count on partner
Unify the behavior for smart buttons on res.partner view form

Let's consider generic records R on a specific model M

- All the R of the children and archived children of a contact C must be counted in smart button of M
in the form of C

- Clicking on the smart button of a contact C must display all R of the children and archived
children of C

closes odoo/odoo#61241

Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
2020-11-03 10:30:44 +00:00

31 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class ResPartner(models.Model):
""" Inherits partner and adds Tasks information in the partner form """
_inherit = 'res.partner'
task_ids = fields.One2many('project.task', 'partner_id', string='Tasks')
task_count = fields.Integer(compute='_compute_task_count', string='# Tasks')
def _compute_task_count(self):
# retrieve all children partners and prefetch 'parent_id' on them
all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
all_partners.read(['parent_id'])
task_data = self.env['project.task'].read_group(
domain=[('partner_id', 'in', all_partners.ids)],
fields=['partner_id'], groupby=['partner_id']
)
self.task_count = 0
for group in task_data:
partner = self.browse(group['partner_id'][0])
while partner:
if partner in self:
partner.task_count += group['partner_id_count']
partner = partner.parent_id