diff --git a/__init__.py b/__init__.py index 30ff37e2fd..afbb97a81f 100644 --- a/__init__.py +++ b/__init__.py @@ -39,9 +39,9 @@ def register(): sale_reporting.CustomerTimeseries, sale_reporting.Product, sale_reporting.ProductTimeseries, - sale_reporting.Category, - sale_reporting.CategoryTimeseries, - sale_reporting.CategoryTree, + sale_reporting.ProductCategory, + sale_reporting.ProductCategoryTimeseries, + sale_reporting.ProductCategoryTree, sale_reporting.Country, sale_reporting.CountryTimeseries, sale_reporting.Subdivision, diff --git a/sale_reporting.py b/sale_reporting.py index aa99ad6218..0a5cd88c99 100644 --- a/sale_reporting.py +++ b/sale_reporting.py @@ -376,7 +376,7 @@ class ProductTimeseries(ProductMixin, AbstractTimeseries, ModelView): __name__ = 'sale.reporting.product.time_series' -class CategoryMixin(object): +class ProductCategoryMixin(object): __slots__ = () category = fields.Many2One( 'product.category', "Category", @@ -390,7 +390,7 @@ class CategoryMixin(object): pool = Pool() Product = pool.get('product.product') TemplateCategory = pool.get('product.template-product.category.all') - from_item, tables, withs = super(CategoryMixin, cls)._joins() + from_item, tables, withs = super()._joins() if 'line.product' not in tables: product = Product.__table__() tables['line.product'] = product @@ -409,7 +409,7 @@ class CategoryMixin(object): @classmethod def _columns(cls, tables, withs): template_category = tables['line.product.template_category'] - return super(CategoryMixin, cls)._columns(tables, withs) + [ + return super()._columns(tables, withs) + [ template_category.category.as_('category')] @classmethod @@ -428,13 +428,12 @@ class CategoryMixin(object): @classmethod def _group_by(cls, tables, withs): template_category = tables['line.product.template_category'] - return super(CategoryMixin, cls)._group_by(tables, withs) + [ - template_category.category] + return super()._group_by(tables, withs) + [template_category.category] @classmethod def _where(cls, tables, withs): template_category = tables['line.product.template_category'] - where = super(CategoryMixin, cls)._where(tables, withs) + where = super()._where(tables, withs) where &= template_category.category != Null return where @@ -442,12 +441,13 @@ class CategoryMixin(object): return self.category.rec_name if self.category else None -class Category(CategoryMixin, Abstract, ModelView): - "Sale Reporting per Category" - __name__ = 'sale.reporting.category' +class ProductCategory(ProductCategoryMixin, Abstract, ModelView): + "Sale Reporting per Product Category" + __name__ = 'sale.reporting.product.category' time_series = fields.One2Many( - 'sale.reporting.category.time_series', 'category', "Time Series") + 'sale.reporting.product.category.time_series', 'category', + "Time Series") @classmethod def __setup__(cls): @@ -460,19 +460,20 @@ class Category(CategoryMixin, Abstract, ModelView): return template_category.category -class CategoryTimeseries(CategoryMixin, AbstractTimeseries, ModelView): - "Sale Reporting per Category" - __name__ = 'sale.reporting.category.time_series' +class ProductCategoryTimeseries( + ProductCategoryMixin, AbstractTimeseries, ModelView): + "Sale Reporting per Product Category" + __name__ = 'sale.reporting.product.category.time_series' -class CategoryTree(ModelSQL, ModelView): - "Sale Reporting per Category" - __name__ = 'sale.reporting.category.tree' +class ProductCategoryTree(ModelSQL, ModelView): + "Sale Reporting per Product Category" + __name__ = 'sale.reporting.product.category.tree' name = fields.Function(fields.Char("Name"), 'get_name') - parent = fields.Many2One('sale.reporting.category.tree', "Parent") + parent = fields.Many2One('sale.reporting.product.category.tree', "Parent") children = fields.One2Many( - 'sale.reporting.category.tree', 'parent', "Children") + 'sale.reporting.product.category.tree', 'parent', "Children") revenue = fields.Function( fields.Numeric("Revenue", digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']), 'get_total') @@ -517,9 +518,9 @@ class CategoryTree(ModelSQL, ModelView): @classmethod def get_total(cls, categories, names): pool = Pool() - ReportingCategory = pool.get('sale.reporting.category') + ReportingProductCategory = pool.get('sale.reporting.product.category') table = cls.__table__() - reporting_category = ReportingCategory.__table__() + reporting_product_category = ReportingProductCategory.__table__() cursor = Transaction().connection.cursor() categories = cls.search([ @@ -527,24 +528,26 @@ class CategoryTree(ModelSQL, ModelView): ]) ids = [c.id for c in categories] parents = {} - reporting_categories = [] + reporting_product_categories = [] for sub_ids in grouped_slice(ids): sub_ids = list(sub_ids) where = reduce_ids(table.id, sub_ids) cursor.execute(*table.select(table.id, table.parent, where=where)) parents.update(cursor) - where = reduce_ids(reporting_category.id, sub_ids) + where = reduce_ids(reporting_product_category.id, sub_ids) cursor.execute( - *reporting_category.select(reporting_category.id, where=where)) - reporting_categories.extend(r for r, in cursor) + *reporting_product_category.select( + reporting_product_category.id, where=where)) + reporting_product_categories.extend(r for r, in cursor) result = {} - reporting_categories = ReportingCategory.browse(reporting_categories) + reporting_product_categories = ReportingProductCategory.browse( + reporting_product_categories) for name in names: values = dict.fromkeys(ids, 0) values.update( - (c.id, getattr(c, name)) for c in reporting_categories) + (c.id, getattr(c, name)) for c in reporting_product_categories) result[name] = cls._sum_tree(categories, values, parents) return result diff --git a/sale_reporting.xml b/sale_reporting.xml index 9857a7fc3e..fb601dec1b 100644 --- a/sale_reporting.xml +++ b/sale_reporting.xml @@ -197,6 +197,10 @@ this repository contains the full copyright notices and license terms. --> Sales per Product sale.reporting.product sale.reporting.context + @@ -218,6 +222,11 @@ this repository contains the full copyright notices and license terms. --> + + tree_open + sale.reporting.product.category.tree,-1 + + User in companies @@ -323,79 +332,79 @@ this repository contains the full copyright notices and license terms. --> - + - - sale.reporting.category.tree + + sale.reporting.product.category.tree tree children - sale_reporting_category_tree + sale_reporting_product_category_tree - - Sales per Category - sale.reporting.category.tree + + Sales per Product Category + sale.reporting.product.category.tree sale.reporting.context - + - - + + - + tree_open - + - - sale.reporting.category + + sale.reporting.product.category tree - sale_reporting_category_list + sale_reporting_product_category_list - - Sales per Category - sale.reporting.category + + Sales per Product Category + sale.reporting.product.category sale.reporting.context - + - - + + - + tree_open - sale.reporting.category.tree,-1 - + sale.reporting.product.category.tree,-1 + - + User in companies - + - + - + - - + + - - + + @@ -403,27 +412,27 @@ this repository contains the full copyright notices and license terms. --> - - sale.reporting.category.time_series + + sale.reporting.product.category.time_series tree - sale_reporting_category_time_series_list + sale_reporting_product_category_time_series_list - - sale.reporting.category.time_series + + sale.reporting.product.category.time_series graph - sale_reporting_category_time_series_graph_revenue + sale_reporting_product_category_time_series_graph_revenue - - sale.reporting.category.time_series + + sale.reporting.product.category.time_series graph - sale_reporting_category_time_series_graph_number + sale_reporting_product_category_time_series_graph_number - - Sales per Category - sale.reporting.category.time_series + + Sales per Product Category + sale.reporting.product.category.time_series sale.reporting.context pyson="1"/> - + - - + + - + - - + + - + - - + + - + tree_open - sale.reporting.category,-1 - + sale.reporting.product.category,-1 + - + User in companies - + - + - + - - + + - - + + diff --git a/tests/scenario_sale_reporting.rst b/tests/scenario_sale_reporting.rst index c4cd3d47c8..11eae34513 100644 --- a/tests/scenario_sale_reporting.rst +++ b/tests/scenario_sale_reporting.rst @@ -183,15 +183,16 @@ Check sale reporting per product:: ... (product1.id, sale2.sale_date.replace(day=1), 1, Decimal('10'))]) True -Check sale reporting per categories:: +Check sale reporting per product categories:: - >>> Category = Model.get('sale.reporting.category') - >>> CategoryTimeseries = Model.get('sale.reporting.category.time_series') - >>> CategoryTree = Model.get('sale.reporting.category.tree') + >>> ProductCategory = Model.get('sale.reporting.product.category') + >>> ProductCategoryTimeseries = Model.get( + ... 'sale.reporting.product.category.time_series') + >>> ProductCategoryTree = Model.get('sale.reporting.product.category.tree') >>> with config.set_context(context=context): - ... reports = Category.find([]) - ... time_series = CategoryTimeseries.find([]) - ... tree = CategoryTree.find([]) + ... reports = ProductCategory.find([]) + ... time_series = ProductCategoryTimeseries.find([]) + ... tree = ProductCategoryTree.find([]) >>> len(reports) 4 >>> with config.set_context(context=context): diff --git a/view/sale_reporting_category_list.xml b/view/sale_reporting_product_category_list.xml similarity index 100% rename from view/sale_reporting_category_list.xml rename to view/sale_reporting_product_category_list.xml diff --git a/view/sale_reporting_category_time_series_graph_number.xml b/view/sale_reporting_product_category_time_series_graph_number.xml similarity index 100% rename from view/sale_reporting_category_time_series_graph_number.xml rename to view/sale_reporting_product_category_time_series_graph_number.xml diff --git a/view/sale_reporting_category_time_series_graph_revenue.xml b/view/sale_reporting_product_category_time_series_graph_revenue.xml similarity index 100% rename from view/sale_reporting_category_time_series_graph_revenue.xml rename to view/sale_reporting_product_category_time_series_graph_revenue.xml diff --git a/view/sale_reporting_category_time_series_list.xml b/view/sale_reporting_product_category_time_series_list.xml similarity index 100% rename from view/sale_reporting_category_time_series_list.xml rename to view/sale_reporting_product_category_time_series_list.xml diff --git a/view/sale_reporting_category_tree.xml b/view/sale_reporting_product_category_tree.xml similarity index 100% rename from view/sale_reporting_category_tree.xml rename to view/sale_reporting_product_category_tree.xml