Skip to content
Browse files

[FIX] sale: SO count

Apply e176749 to SO count in order to
take into account all children, and not only direct children.

  • Loading branch information...
nim-odoo committed Feb 21, 2019
1 parent bed3b4a commit 3ab0e3daed83a3c19265520ebcdf45da899e0a70
Showing with 14 additions and 8 deletions.
  1. +14 −8 addons/sale/models/
@@ -14,11 +14,17 @@ class ResPartner(models.Model):
sale_warn_msg = fields.Text('Message for Sales Order')

def _compute_sale_order_count(self):
sale_data = self.env['sale.order'].read_group(domain=[('partner_id', 'child_of', self.ids)],
fields=['partner_id'], groupby=['partner_id'])
mapped_data = dict([(m['partner_id'][0], m['partner_id_count']) for m in sale_data])
for partner in self:
# let's obtain the partner id and all its child ids
partner_ids = [] + partner.child_ids.ids
# then we can sum for all the partner's child
partner.sale_order_count = sum(mapped_data.get(child, 0) for child in partner_ids)
# retrieve all children partners and prefetch 'parent_id' on them
all_partners =[('id', 'child_of', self.ids)])['parent_id'])

sale_order_groups = self.env['sale.order'].read_group(
domain=[('partner_id', 'in', all_partners.ids)],
fields=['partner_id'], groupby=['partner_id']
for group in sale_order_groups:
partner = self.browse(group['partner_id'][0])
while partner:
if partner in self:
partner.sale_order_count += group['partner_id_count']
partner = partner.parent_id

0 comments on commit 3ab0e3d

Please sign in to comment.
You can’t perform that action at this time.