[MIG] pos_usability to v16

This commit is contained in:
Alexis de Lattre
2023-03-17 10:20:29 +00:00
parent b954772126
commit 1e19fc906c
7 changed files with 18 additions and 26 deletions

View File

@@ -11,15 +11,18 @@ class PosCategory(models.Model):
product_count = fields.Integer(
'# Products', compute='_compute_product_count',
help="The number of products under this point of sale category "
"(does not consider the children categories)")
"(children categories included)")
# inspired by the code of odoo/addons/product/models/product.py
# inspired by the code of odoo/addons/product/models/product_category.py
def _compute_product_count(self):
read_group_res = self.env['product.template'].read_group(
[('pos_categ_id', 'in', self.ids)],
[('pos_categ_id', 'child_of', self.ids)],
['pos_categ_id'], ['pos_categ_id'])
group_data = dict(
(data['pos_categ_id'][0], data['pos_categ_id_count']) for data
in read_group_res)
for pos_categ in self:
pos_categ.product_count = group_data.get(pos_categ.id, 0)
product_count = 0
for sub_categ_id in pos_categ.search([('id', 'child_of', pos_categ.ids)]).ids:
product_count += group_data.get(sub_categ_id, 0)
pos_categ.product_count = product_count