From 074f4e517a1b6d3ec4825705d97c74455e90f665 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 7 Dec 2017 13:50:46 +0100 Subject: [PATCH] pos_usability: add group by on pos category on products search view Add link to products from pos.category form view (same as on product.category form view) --- pos_usability/__init__.py | 1 + pos_usability/__manifest__.py | 10 ++++++-- pos_usability/pos.py | 25 ++++++++++++++++++++ pos_usability/pos_view.xml | 28 ++++++++++++++--------- pos_usability/product_view.xml | 42 ++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 pos_usability/pos.py create mode 100644 pos_usability/product_view.xml diff --git a/pos_usability/__init__.py b/pos_usability/__init__.py index d7d7308..11fbc8e 100644 --- a/pos_usability/__init__.py +++ b/pos_usability/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +from . import pos from . import product diff --git a/pos_usability/__manifest__.py b/pos_usability/__manifest__.py index 2472788..3be539d 100644 --- a/pos_usability/__manifest__.py +++ b/pos_usability/__manifest__.py @@ -18,7 +18,13 @@ This module has been written by Alexis de Lattre from Akretion ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class PosCategory(models.Model): + _inherit = 'pos.category' + + 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)") + + # inspired by the code of odoo/addons/product/models/product.py + def _compute_product_count(self): + read_group_res = self.env['product.template'].read_group( + [('pos_categ_id', 'in', 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) diff --git a/pos_usability/pos_view.xml b/pos_usability/pos_view.xml index be45b10..de07928 100644 --- a/pos_usability/pos_view.xml +++ b/pos_usability/pos_view.xml @@ -36,19 +36,25 @@ - - - usability.pos.product.template - product.template - + + pos.category.form + pos.category + - - -
- - diff --git a/pos_usability/product_view.xml b/pos_usability/product_view.xml new file mode 100644 index 0000000..f5313d1 --- /dev/null +++ b/pos_usability/product_view.xml @@ -0,0 +1,42 @@ + + + + + + + + + + usability.pos.product.template + product.template + + + + +
+ +
+
+
+
+ + + pos_usability.product.template.search + product.template + + + + + + + + + + + + +