From 287d55fd6b9bcc529495e769711da81ad2b63be8 Mon Sep 17 00:00:00 2001 From: Mateu Griful Date: Thu, 25 Feb 2021 13:43:23 +0100 Subject: [PATCH] [MIG] stock_pull_list: Migration to 14.0 --- stock_pull_list/__manifest__.py | 9 ++-- stock_pull_list/security/ir.model.access.csv | 5 +++ stock_pull_list/tests/common.py | 1 - stock_pull_list/tests/test_stock_pull_list.py | 6 +-- .../wizards/stock_pull_list_wizard.py | 42 ++++++++----------- .../wizards/stock_pull_list_wizard.xml | 18 ++++---- 6 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 stock_pull_list/security/ir.model.access.csv diff --git a/stock_pull_list/__manifest__.py b/stock_pull_list/__manifest__.py index 14f8413e8..95c7e23b9 100644 --- a/stock_pull_list/__manifest__.py +++ b/stock_pull_list/__manifest__.py @@ -5,14 +5,17 @@ "name": "Stock Pull List", "summary": "The pull list checks the stock situation and calculates " "needed quantities.", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "license": "LGPL-3", "website": "https://github.com/OCA/stock-logistics-warehouse", "author": "ForgeFlow, " "Odoo Community Association (OCA)", "maintainers": ["LoisRForgeFlow"], "development_status": "Alpha", "category": "Warehouse Management", - "depends": ["stock", "stock_available_unreserved"], - "data": ["wizards/stock_pull_list_wizard.xml"], + "depends": ["stock", "stock_free_quantity"], + "data": [ + "wizards/stock_pull_list_wizard.xml", + "security/ir.model.access.csv", + ], "installable": True, } diff --git a/stock_pull_list/security/ir.model.access.csv b/stock_pull_list/security/ir.model.access.csv new file mode 100644 index 000000000..f9048329e --- /dev/null +++ b/stock_pull_list/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wiz_stock_pull_list_user,access_wiz_stock_pull_list_user,model_stock_pull_list_wizard,stock.group_stock_user,1,1,1,1 +access_wiz_stock_pull_list_manager,access_wiz_stock_pull_list_manager,model_stock_pull_list_wizard,stock.group_stock_manager,1,1,1,1 +access_wiz_stock_pull_list_line_user,access_wiz_stock_pull_list_line_user,model_stock_pull_list_wizard_line,stock.group_stock_user,1,1,1,1 +access_wiz_stock_pull_list_line_manager,access_wiz_stock_pull_list_line_manager,model_stock_pull_list_wizard_line,stock.group_stock_manager,1,1,1,1 diff --git a/stock_pull_list/tests/common.py b/stock_pull_list/tests/common.py index 4fb2e46c1..fc02af3ed 100644 --- a/stock_pull_list/tests/common.py +++ b/stock_pull_list/tests/common.py @@ -67,7 +67,6 @@ class TestPullListCommon(TransactionCase): { "name": "Test move", "product_id": self.product_a.id, - "date_expected": date_move, "date": date_move, "product_uom": self.product_a.uom_id.id, "product_uom_qty": qty, diff --git a/stock_pull_list/tests/test_stock_pull_list.py b/stock_pull_list/tests/test_stock_pull_list.py index e9bd3283e..e1198face 100644 --- a/stock_pull_list/tests/test_stock_pull_list.py +++ b/stock_pull_list/tests/test_stock_pull_list.py @@ -11,12 +11,12 @@ class TestStockPullList(TestPullListCommon): wiz.action_prepare() lines = wiz.line_ids.filtered(lambda l: l.product_id == self.product_a) self.assertEqual(len(lines), 2) - line_1 = lines.filtered(lambda l: l.date_expected == self.yesterday.date()) + line_1 = lines.filtered(lambda l: l.date == self.yesterday.date()) self.assertEqual(line_1.raw_demand_qty, 50) self.assertEqual(line_1.needed_qty, 50) self.assertEqual(line_1.stock_rule_id, self.transfer_rule) - line_2 = lines.filtered(lambda l: l.date_expected == self.date_3.date()) + line_2 = lines.filtered(lambda l: l.date == self.date_3.date()) self.assertEqual(line_2.raw_demand_qty, 70) self.assertEqual(line_2.needed_qty, 70) @@ -26,7 +26,7 @@ class TestStockPullList(TestPullListCommon): wiz.action_prepare() line = wiz.line_ids.filtered(lambda l: l.product_id == self.product_a) self.assertEqual(len(line), 1) - self.assertEqual(line.date_expected, self.today.date()) + self.assertEqual(line.date, self.today.date()) expected = 50 + 70 self.assertEqual(line.raw_demand_qty, expected) self.assertEqual(line.needed_qty, expected) diff --git a/stock_pull_list/wizards/stock_pull_list_wizard.py b/stock_pull_list/wizards/stock_pull_list_wizard.py index 6352b2a3e..f581f8d2c 100644 --- a/stock_pull_list/wizards/stock_pull_list_wizard.py +++ b/stock_pull_list/wizards/stock_pull_list_wizard.py @@ -5,6 +5,7 @@ import itertools from odoo import _, api, fields, models from odoo.exceptions import UserError +from odoo.tools import float_compare class PullListWizard(models.TransientModel): @@ -69,7 +70,7 @@ class PullListWizard(models.TransientModel): if self.exclude_reserved: domain.append(("state", "not in", ("assigned",))) if self.date_to: - domain.append(("date_expected", "<=", self.date_to)) + domain.append(("date", "<=", self.date_to)) if self.procurement_group_ids: domain.append(("group_id", "in", self.procurement_group_ids.ids)) return domain @@ -81,12 +82,12 @@ class PullListWizard(models.TransientModel): ("state", "not in", ("draft", "done", "cancel")), ] if self.date_to: - domain.append(("date_expected", "<=", self.date_to)) + domain.append(("date", "<=", self.date_to)) return domain @api.model def _prepare_line_values(self, key, demand_qty, supply_qty): - product, location, date_expected = key + product, location, date = key rule = self._get_stock_rule_id(product, location) global qty_assigned prev = qty_assigned.setdefault(product, 0.0) @@ -98,7 +99,7 @@ class PullListWizard(models.TransientModel): return { "product_id": product.id if product else False, "location_id": location.id if location else False, - "date_expected": date_expected, + "date": date, "stock_rule_id": rule.id if rule else False, "raw_demand_qty": demand_qty, "available_qty": qty_available, @@ -112,7 +113,7 @@ class PullListWizard(models.TransientModel): product.id ) if self.exclude_reserved: - return product_l.qty_available_not_res + return product_l.free_qty return product_l.qty_available @api.model @@ -130,35 +131,28 @@ class PullListWizard(models.TransientModel): domain = self._get_moves_demand_domain() # `read_group` is not possible here because of the date format the # method returns. - demand_moves = self.env["stock.move"].search(domain, order="date_expected asc") + demand_moves = self.env["stock.move"].search(domain, order="date asc") demand_dict = {} force_date = fields.Date.today() if self.consolidate_by_product else False for demand in demand_moves: key = ( demand.product_id, demand.location_id, - fields.Date.to_date(demand.date_expected) - if not force_date - else force_date, + fields.Date.to_date(demand.date) if not force_date else force_date, ) prev = demand_dict.setdefault(key, 0.0) # TODO: when exclude_reserved is selected, handle partially avail. demand_dict[key] = prev + demand.product_uom_qty domain = self._get_moves_incoming_domain() - incoming_moves = self.env["stock.move"].search( - domain, order="date_expected asc" - ) + incoming_moves = self.env["stock.move"].search(domain, order="date asc") incoming_dict = {} for supply in incoming_moves: move_for_date = demand_moves.filtered( - lambda m: m.product_id == supply.product_id - and m.date_expected >= supply.date_expected + lambda m: m.product_id == supply.product_id and m.date >= supply.date ) if move_for_date: - date_selected = ( - move_for_date[0].date_expected if not force_date else force_date - ) + date_selected = move_for_date[0].date if not force_date else force_date else: # Supply is later than last demand -> ignore it. continue @@ -273,7 +267,7 @@ class PullListWizard(models.TransientModel): group = pg_obj.create(self._prepare_proc_group_values()) proc_groups.append(group.id) - values = self._prepare_procurement_values(line.date_expected, group) + values = self._prepare_procurement_values(line.date, group) procurements.append( pg_obj.Procurement( line.product_id, @@ -318,11 +312,11 @@ class PullListWizardLine(models.TransientModel): location_id = fields.Many2one( comodel_name="stock.location", ) - date_expected = fields.Date() - available_qty = fields.Float() - incoming_qty = fields.Float() - raw_demand_qty = fields.Float() - needed_qty = fields.Float() + date = fields.Date() + available_qty = fields.Float(digits="Product Unit of Measure") + incoming_qty = fields.Float(digits="Product Unit of Measure") + raw_demand_qty = fields.Float(digits="Product Unit of Measure") + needed_qty = fields.Float(digits="Product Unit of Measure") stock_rule_id = fields.Many2one( comodel_name="stock.rule", ) @@ -334,4 +328,4 @@ class PullListWizardLine(models.TransientModel): qty_avail = self.wizard_id._get_available_qty( self.product_id, self.stock_rule_id.location_src_id ) - return qty_avail > self.needed_qty + return float_compare(qty_avail, self.needed_qty, precision_digits=2) > 0 diff --git a/stock_pull_list/wizards/stock_pull_list_wizard.xml b/stock_pull_list/wizards/stock_pull_list_wizard.xml index 239aa7ef4..ff75540b6 100644 --- a/stock_pull_list/wizards/stock_pull_list_wizard.xml +++ b/stock_pull_list/wizards/stock_pull_list_wizard.xml @@ -55,7 +55,7 @@ - + @@ -112,14 +112,14 @@ - + + Generate Pull List + stock.pull.list.wizard + + form + new + +