From 9948e15d09a166adbd3011be157feedde2ec0546 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Tue, 15 Nov 2022 08:24:07 +0100 Subject: [PATCH] [IMP] product_abc_classification_sale_stock: pre-commit stuff --- .../__manifest__.py | 1 - .../demo/abc_classification_level.xml | 2 +- .../demo/abc_classification_profile.xml | 9 ++- .../abc_classification_product_level.py | 1 - .../models/abc_classification_profile.py | 48 ++++++--------- .../models/abc_sale_stock_level_history.py | 19 +++--- .../security/abc_sale_stock_level_history.xml | 24 +++++--- .../tests/test_abc_classification_profile.py | 2 - .../abc_classification_product_level.xml | 34 +++++++---- .../views/abc_classification_profile.xml | 14 ++++- .../views/abc_sale_stock_level_history.xml | 61 +++++++++++-------- 11 files changed, 119 insertions(+), 96 deletions(-) diff --git a/product_abc_classification_sale_stock/__manifest__.py b/product_abc_classification_sale_stock/__manifest__.py index dff75041bed..231beeaaa34 100644 --- a/product_abc_classification_sale_stock/__manifest__.py +++ b/product_abc_classification_sale_stock/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/product_abc_classification_sale_stock/demo/abc_classification_level.xml b/product_abc_classification_sale_stock/demo/abc_classification_level.xml index 6777e316af8..d009df5b7d4 100644 --- a/product_abc_classification_sale_stock/demo/abc_classification_level.xml +++ b/product_abc_classification_sale_stock/demo/abc_classification_level.xml @@ -1,4 +1,4 @@ - + diff --git a/product_abc_classification_sale_stock/demo/abc_classification_profile.xml b/product_abc_classification_sale_stock/demo/abc_classification_profile.xml index aee51147dcb..3119ed5e154 100644 --- a/product_abc_classification_sale_stock/demo/abc_classification_profile.xml +++ b/product_abc_classification_sale_stock/demo/abc_classification_profile.xml @@ -1,12 +1,15 @@ - + Sale stock profile sale_stock - + 365 - + diff --git a/product_abc_classification_sale_stock/models/abc_classification_product_level.py b/product_abc_classification_sale_stock/models/abc_classification_product_level.py index c59b9740ead..13c585502b5 100644 --- a/product_abc_classification_sale_stock/models/abc_classification_product_level.py +++ b/product_abc_classification_sale_stock/models/abc_classification_product_level.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/product_abc_classification_sale_stock/models/abc_classification_profile.py b/product_abc_classification_sale_stock/models/abc_classification_profile.py index c38641fc6e4..a00020c6aa5 100644 --- a/product_abc_classification_sale_stock/models/abc_classification_profile.py +++ b/product_abc_classification_sale_stock/models/abc_classification_profile.py @@ -1,15 +1,15 @@ -# -*- coding: utf-8 -*- # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import csv -from cStringIO import StringIO from datetime import datetime, timedelta from operator import attrgetter +from cStringIO import StringIO + from odoo import _, api, fields, models -from odoo.tools import float_round from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_round class AbcClassificationProfile(models.Model): @@ -38,9 +38,9 @@ def _check_warehouse_id(self): for rec in self: if rec.profile_type == "sale_stock" and not rec.warehouse_id: raise ValidationError( - _( - "You must specify a warehouse for {profile_name}" - ).forman(profile_name=rec.name) + _("You must specify a warehouse for {profile_name}").forman( + profile_name=rec.name + ) ) @api.model @@ -74,8 +74,7 @@ def _get_all_product_ids(self): return {r[0] for r in self.env.cr.fetchall()} def _get_data(self, from_date=None): - """Get a list of statics info from the DB ordered by number of lines desc - """ + """Get a list of statics info from the DB ordered by number of lines desc""" self.ensure_one() from_date = ( from_date @@ -176,9 +175,7 @@ def _build_ordered_level_cumulative_percentage(self): The ordering is based on the level with the higher percentage first """ self.ensure_one() - levels = self.level_ids.sorted( - key=attrgetter("percentage"), reverse=True - ) + levels = self.level_ids.sorted(key=attrgetter("percentage"), reverse=True) cum_percentages = [] previous_percentage = None for i, level in enumerate(levels): @@ -235,7 +232,7 @@ def _sale_stock_data_to_vals(self, sale_stock_data, create=False): @api.multi def _compute_abc_classification(self): - to_compute = self.filtered((lambda p: p.profile_type == "sale_stock")) + to_compute = self.filtered(lambda p: p.profile_type == "sale_stock") remaining = self - to_compute res = None if remaining: @@ -247,9 +244,7 @@ def _compute_abc_classification(self): for profile in to_compute: sale_stock_data_list, total = profile._get_data() existing_level_ids_to_remove = profile._get_existing_level_ids() - level_percentage = ( - profile._build_ordered_level_cumulative_percentage() - ) + level_percentage = profile._build_ordered_level_cumulative_percentage() level, percentage = level_percentage.pop(0) previous_data = {} total_products = len(sale_stock_data_list) @@ -267,23 +262,18 @@ def _compute_abc_classification(self): ) # Compute percentages and cumulative percentages for the products sale_stock_data.percentage = ( - (100.0 * sale_stock_data.number_so_lines / total) - if total - else 0.0 + (100.0 * sale_stock_data.number_so_lines / total) if total else 0.0 ) sale_stock_data.cumulated_percentage = ( sale_stock_data.percentage if i == 0 else ( - sale_stock_data.percentage - + previous_data.cumulated_percentage + sale_stock_data.percentage + previous_data.cumulated_percentage ) ) if float_round(sale_stock_data.cumulated_percentage, 0) > 100: - raise UserError( - _("Cumulative percentage greater than 100.") - ) + raise UserError(_("Cumulative percentage greater than 100.")) sale_stock_data.sum_cumulated_percentages = ( sale_stock_data.cumulated_percentage @@ -308,9 +298,7 @@ def _compute_abc_classification(self): sale_stock_data.computed_level = level if product_abc_classification: # The line is still significant... - existing_level_ids_to_remove.remove( - product_abc_classification.id - ) + existing_level_ids_to_remove.remove(product_abc_classification.id) if product_abc_classification.level_id != level: vals = profile._sale_stock_data_to_vals( sale_stock_data, create=False @@ -320,9 +308,7 @@ def _compute_abc_classification(self): vals = profile._sale_stock_data_to_vals( sale_stock_data, create=True ) - product_abc_classification = ProductClassification.create( - vals - ) + product_abc_classification = ProductClassification.create(vals) sale_stock_data.total_so_lines = total sale_stock_data.product_level = product_abc_classification previous_data = sale_stock_data @@ -331,7 +317,7 @@ def _compute_abc_classification(self): return res def _log_history(self, sale_stock_data_list): - """ Log collected and computed values into + """Log collected and computed values into abc.sale_stock.level.history """ @@ -349,7 +335,7 @@ def _log_history(self, sale_stock_data_list): class SaleStockData(object): - """ Sale stock collected data + """Sale stock collected data This class is used to store all the data collectd and computed for a abc classification product level. It also provide methods used to bulk diff --git a/product_abc_classification_sale_stock/models/abc_sale_stock_level_history.py b/product_abc_classification_sale_stock/models/abc_sale_stock_level_history.py index 301e089a643..edfd4638e51 100644 --- a/product_abc_classification_sale_stock/models/abc_sale_stock_level_history.py +++ b/product_abc_classification_sale_stock/models/abc_sale_stock_level_history.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -6,7 +5,7 @@ class AbcSaleStockLevelHistory(models.Model): - """ ABC Classification Product Level History + """ABC Classification Product Level History This model is used to display the history of values collected and involved into the computation of the ABC classification level. @@ -61,7 +60,10 @@ class AbcSaleStockLevelHistory(models.Model): ondelete="cascade", ) warehouse_id = fields.Many2one( - "stock.warehouse", "Warehouse", readonly=False, ondelete="cascade", + "stock.warehouse", + "Warehouse", + readonly=False, + ondelete="cascade", ) ranking = fields.Integer( "Ranking", @@ -70,10 +72,14 @@ class AbcSaleStockLevelHistory(models.Model): help="Ranking by number of oder lines", ) number_so_lines = fields.Integer( - "Number of sale order lines", required=True, readonly=True, + "Number of sale order lines", + required=True, + readonly=True, ) total_so_lines = fields.Integer( - "Total of sale order lines", required=True, readonly=True, + "Total of sale order lines", + required=True, + readonly=True, ) percentage = fields.Float( "Percentage", @@ -109,8 +115,7 @@ class AbcSaleStockLevelHistory(models.Model): "Cumulated percentage of products", required=True, readonly=True, - help="Cumulated percentage of total products analyzed with a " - "better ranking", + help="Cumulated percentage of total products analyzed with a " "better ranking", digits=(7, 4), group_operator=None, ) diff --git a/product_abc_classification_sale_stock/security/abc_sale_stock_level_history.xml b/product_abc_classification_sale_stock/security/abc_sale_stock_level_history.xml index 0b2310cf480..10d9df47567 100644 --- a/product_abc_classification_sale_stock/security/abc_sale_stock_level_history.xml +++ b/product_abc_classification_sale_stock/security/abc_sale_stock_level_history.xml @@ -1,18 +1,22 @@ - + - - - abc.sale_stock.level.history access name - + + abc.sale_stock.level.history access name + - - - - - + + + + + diff --git a/product_abc_classification_sale_stock/tests/test_abc_classification_profile.py b/product_abc_classification_sale_stock/tests/test_abc_classification_profile.py index 6976a034599..91c799f9636 100644 --- a/product_abc_classification_sale_stock/tests/test_abc_classification_profile.py +++ b/product_abc_classification_sale_stock/tests/test_abc_classification_profile.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2021 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -275,4 +274,3 @@ def test_02(self): self.assertEqual(len(levels.sale_stock_level_history_ids), 1) self.stock_profile._compute_abc_classification() self.assertEqual(len(levels.sale_stock_level_history_ids), 2) - diff --git a/product_abc_classification_sale_stock/views/abc_classification_product_level.xml b/product_abc_classification_sale_stock/views/abc_classification_product_level.xml index 4c42652174a..4e404356cbf 100644 --- a/product_abc_classification_sale_stock/views/abc_classification_product_level.xml +++ b/product_abc_classification_sale_stock/views/abc_classification_product_level.xml @@ -1,26 +1,34 @@ - + - - abc.classification.product.level.form (in product_abc_classification_sale_stock) + abc.classification.product.level.form (in product_abc_classification_sale_stock) abc.classification.product.level - + - + - - - - - - - - + + + + + + + + diff --git a/product_abc_classification_sale_stock/views/abc_classification_profile.xml b/product_abc_classification_sale_stock/views/abc_classification_profile.xml index ccaa0f9f654..86082798887 100644 --- a/product_abc_classification_sale_stock/views/abc_classification_profile.xml +++ b/product_abc_classification_sale_stock/views/abc_classification_profile.xml @@ -3,12 +3,20 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> - abc.classification.profile.form (in product_abc_classification_sale_stock) + abc.classification.profile.form (in product_abc_classification_sale_stock) abc.classification.profile - + - + diff --git a/product_abc_classification_sale_stock/views/abc_sale_stock_level_history.xml b/product_abc_classification_sale_stock/views/abc_sale_stock_level_history.xml index 27b8e73e1d7..1c8a2cb1975 100644 --- a/product_abc_classification_sale_stock/views/abc_sale_stock_level_history.xml +++ b/product_abc_classification_sale_stock/views/abc_sale_stock_level_history.xml @@ -1,42 +1,55 @@ - + - - abc.sale_stock.level.history.search (in product_abc_classification_sale_stock) + abc.sale_stock.level.history.search (in product_abc_classification_sale_stock) abc.sale_stock.level.history - - - - + + + + - + - abc.sale_stock.level.history.tree (in product_abc_classification_sale_stock) + abc.sale_stock.level.history.tree (in product_abc_classification_sale_stock) abc.sale_stock.level.history - - - - - - - - - - - - + + + + + + + + + + + + @@ -51,9 +64,9 @@ Abc Sale_stock Level History - - - + + +