From d523be434817686fc88c9870dc2ee11d63ff1887 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 12:06:08 +0100 Subject: [PATCH 01/21] TA#70584 [14.0][DEL] stock_location_production --- .docker_files/main/__manifest__.py | 1 - Dockerfile | 1 - project_material/__manifest__.py | 1 - project_material/models/stock_warehouse.py | 8 +++++--- .../tests/test_consumption_route.py | 8 +++++--- stock_location_production/README.rst | 7 ------- stock_location_production/__init__.py | 2 -- stock_location_production/__manifest__.py | 18 ------------------ stock_location_production/data/stock_data.xml | 11 ----------- .../static/description/icon.png | 0 10 files changed, 10 insertions(+), 47 deletions(-) delete mode 100644 stock_location_production/README.rst delete mode 100644 stock_location_production/__init__.py delete mode 100644 stock_location_production/__manifest__.py delete mode 100644 stock_location_production/data/stock_data.xml delete mode 100644 stock_location_production/static/description/icon.png diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index f28cd0e3..d6e3179c 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -70,7 +70,6 @@ "project_time_range", "project_timesheet_analytic_update", "project_type", - "stock_location_production", "project_wip", "project_wip_material", "timesheet_task_project_no_change", diff --git a/Dockerfile b/Dockerfile index 29851345..aca0f8ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -72,7 +72,6 @@ COPY project_timesheet_analytic_update /mnt/extra-addons/project_timesheet_anal COPY project_type /mnt/extra-addons/project_type COPY project_wip /mnt/extra-addons/project_wip COPY project_wip_material /mnt/extra-addons/project_wip_material -COPY stock_location_production /mnt/extra-addons/stock_location_production COPY timesheet_task_project_no_change /mnt/extra-addons/timesheet_task_project_no_change diff --git a/project_material/__manifest__.py b/project_material/__manifest__.py index 01cb9680..191c4df9 100644 --- a/project_material/__manifest__.py +++ b/project_material/__manifest__.py @@ -12,7 +12,6 @@ "summary": "Consume material on projects", "depends": [ "project_task_date_planned", - "stock_location_production", "stock_account", "purchase_stock", ], diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 4b97ba03..ef4464b4 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -14,9 +14,11 @@ class Warehouse(models.Model): _inherit = "stock.warehouse" def _get_default_consumption_location_id(self): - return self.env.ref( - "stock_location_production.location_production", raise_if_not_found=False - ).id + property_stock_production = self.env['ir.property'].sudo().search( + [('name', '=', 'property_stock_production'), + ('company_id', '=',self.env.company.id)]) + location_id = property_stock_production.value_reference.split(',')[-1] + return location_id consu_steps = fields.Selection( [(ONE_STEP_KEY, ONE_STEP_DESCRIPTION)], default=ONE_STEP_KEY diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index e6ce73dd..db995743 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -17,13 +17,15 @@ def setUpClass(cls): cls.new_warehouse = cls.env["stock.warehouse"].search( [("company_id", "=", cls.new_company.id)], limit=1 ) + property_stock_production = cls.env['ir.property'].sudo().search( + [('name', '=', 'property_stock_production'), + ('company_id', '=', cls.env.user.company_id.id)]) + cls.location_id = property_stock_production.value_reference.split(',')[-1] class TestConsumptionStep(ConsumptionRouteCase): def test_default_consumption_location(self): - assert self.new_warehouse.consu_location_id == self.env.ref( - "stock_location_production.location_production" - ) + assert self.new_warehouse.consu_location_id.id == self.location_id def test_main_warehouse_has_consumption_route(self): assert self.main_warehouse.consu_route_id diff --git a/stock_location_production/README.rst b/stock_location_production/README.rst deleted file mode 100644 index 202d327b..00000000 --- a/stock_location_production/README.rst +++ /dev/null @@ -1,7 +0,0 @@ -Stock Picking Split Quantity -============================ -This module adds a Production Stock Location data. - -Contributors ------------- -* Numigi (tm) and all its contributors (https://bit.ly/numigiens) diff --git a/stock_location_production/__init__.py b/stock_location_production/__init__.py deleted file mode 100644 index 0ab5e8ea..00000000 --- a/stock_location_production/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# © 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/stock_location_production/__manifest__.py b/stock_location_production/__manifest__.py deleted file mode 100644 index 26466bd5..00000000 --- a/stock_location_production/__manifest__.py +++ /dev/null @@ -1,18 +0,0 @@ -# © 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -{ - "name": "Stock Location Production", - "version": "1.0.0", - "author": "Numigi", - "maintainer": "Numigi", - "website": "https://bit.ly/numigi-com", - "license": "AGPL-3", - "category": "Stock", - "depends": ["stock"], - "summary": """ - Add a Production Stock Location data. - """, - "data": ["data/stock_data.xml"], - "installable": True, -} diff --git a/stock_location_production/data/stock_data.xml b/stock_location_production/data/stock_data.xml deleted file mode 100644 index 157b1f05..00000000 --- a/stock_location_production/data/stock_data.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Production - - production - - - - \ No newline at end of file diff --git a/stock_location_production/static/description/icon.png b/stock_location_production/static/description/icon.png deleted file mode 100644 index e69de29b..00000000 From c30f1872d136fb5e49329addb23c4cf4c9bd1a8e Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 12:27:32 +0100 Subject: [PATCH 02/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index ef4464b4..3c6903b1 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -16,7 +16,7 @@ class Warehouse(models.Model): def _get_default_consumption_location_id(self): property_stock_production = self.env['ir.property'].sudo().search( [('name', '=', 'property_stock_production'), - ('company_id', '=',self.env.company.id)]) + ('company_id', '=', self.env.company.id)]) location_id = property_stock_production.value_reference.split(',')[-1] return location_id From fc363116fac9e7957e7b471551ebe3472baa6c2c Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 14:37:16 +0100 Subject: [PATCH 03/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 3c6903b1..e6eb8632 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -105,7 +105,7 @@ def _get_consumption_picking_type_create_values(self): vals.update( { "name": _("Consumption"), - "company_id": self.company_id.id, + "company_id": self.env.company.id, "use_create_lots": True, "sequence_code": "CO", "use_existing_lots": True, @@ -122,7 +122,7 @@ def _get_consumption_return_picking_type_create_values(self): "name": _("Consumption Return"), "use_create_lots": False, "use_existing_lots": False, - "company_id": self.company_id.id, + "company_id": self.env.company.id, "sequence_code": "COR", "sequence": 101, "sequence_id": self._create_consumption_return_sequence().id, @@ -171,7 +171,7 @@ def _get_consumption_sequence_values(self): "name": "{}: Consumption".format(self.name), "prefix": "{}/CO/".format(self.code), "padding": 5, - "company_id": self.company_id.id, + "company_id": self.env.company.id, } def _get_consumption_return_sequence_values(self): @@ -179,7 +179,7 @@ def _get_consumption_return_sequence_values(self): "name": "{}: Consumption Return".format(self.name), "prefix": "{}/COR/".format(self.code), "padding": 5, - "company_id": self.company_id.id, + "company_id": self.env.company.id, } def _create_or_update_consumption_route(self): @@ -206,7 +206,7 @@ def _get_consumption_route_values(self): description=self._get_consumption_route_description(), ), "active": True, - "company_id": self.company_id.id, + "company_id": self.env.company.id, "product_categ_selectable": True, "warehouse_selectable": True, "product_selectable": False, @@ -245,7 +245,7 @@ def _get_consumption_pull_values(self): "picking_type_id": self.consu_type_id.id, "action": "pull", "active": True, - "company_id": self.company_id.id, + "company_id": self.env.company.id, "sequence": 1, "propagate_cancel": True, "procure_method": procure_method, @@ -276,7 +276,7 @@ def _get_consumption_mto_pull_vals(self): "picking_type_id": self.consu_type_id.id, "action": "pull", "active": True, - "company_id": self.company_id.id, + "company_id": self.env.company.id, "sequence": 1, "propagate_cancel": True, "procure_method": "make_to_order", @@ -355,7 +355,7 @@ def _get_consumption_prep_pull_values(self): "picking_type_id": self.consu_prep_type_id.id, "action": "pull", "active": True, - "company_id": self.company_id.id, + "company_id": self.env.company.id, "sequence": 2, "propagate_cancel": True, "procure_method": "make_to_stock", From f67c6ed4613990e9a65f8732a84ca89c1c5c91ff Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:13:34 +0100 Subject: [PATCH 04/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/init_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_material/init_hook.py b/project_material/init_hook.py index fff20738..ac0126c6 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -10,7 +10,7 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): - warehouses = env["stock.warehouse"].search([]) + warehouses = env["stock.warehouse"].with_context(company_id=env.company.id).search([]) for warehouse in warehouses: warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() From 9d0442a3150f71e97c4a272e4a4c17f296945830 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:20:40 +0100 Subject: [PATCH 05/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/init_hook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_material/init_hook.py b/project_material/init_hook.py index ac0126c6..0731b182 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -12,5 +12,5 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): warehouses = env["stock.warehouse"].with_context(company_id=env.company.id).search([]) for warehouse in warehouses: - warehouse._create_or_update_consumption_picking_types() - warehouse._create_or_update_consumption_route() + warehouse.with_context(company_id=env.company.id)._create_or_update_consumption_picking_types() + warehouse.with_context(company_id=env.company.id)._create_or_update_consumption_route() From 5877377aec4ad069ee2a063a09b9e7665f74d82e Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:24:09 +0100 Subject: [PATCH 06/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index e6eb8632..8e45e78b 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -329,7 +329,7 @@ def _update_consumption_route(self): def _update_consumption_prep_pull(self): existing_pull = self.consu_route_id.with_context( - active_test=False + active_test=False,company_id = self.env.company.id ).rule_ids.filtered(lambda p: p.location_id == self.consu_prep_location_id) pull_required = self._has_two_steps_consumption() From a44126ace4d6b8a2baf1766e9147c664894a73e3 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:32:50 +0100 Subject: [PATCH 07/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/init_hook.py | 6 +++--- project_material/models/stock_warehouse.py | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/project_material/init_hook.py b/project_material/init_hook.py index 0731b182..fff20738 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -10,7 +10,7 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): - warehouses = env["stock.warehouse"].with_context(company_id=env.company.id).search([]) + warehouses = env["stock.warehouse"].search([]) for warehouse in warehouses: - warehouse.with_context(company_id=env.company.id)._create_or_update_consumption_picking_types() - warehouse.with_context(company_id=env.company.id)._create_or_update_consumption_route() + warehouse._create_or_update_consumption_picking_types() + warehouse._create_or_update_consumption_route() diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 8e45e78b..eca38ffb 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -150,11 +150,14 @@ def _get_consumption_return_picking_type_values(self): return { "warehouse_id": self.id, "code": "consumption_return", - "default_location_src_id": self.consu_location_id.id, + "default_location_src_id": self.with_context( + company_id=self.env.company.id).consu_location_id.id, "default_location_dest_id": ( - self.lot_stock_id.id + self.with_context( + company_id=self.env.company.id).lot_stock_id.id if self._has_one_step_consumption() - else self.consu_prep_location_id.id + else self.with_context( + company_id=self.env.company.id).consu_prep_location_id.id ), } @@ -444,16 +447,20 @@ def _get_consumption_prep_picking_type_values(self): return { "warehouse_id": self.id, "code": "internal", - "default_location_src_id": self.lot_stock_id.id, - "default_location_dest_id": self.consu_prep_location_id.id, + "default_location_src_id": self.with_context( + company_id=self.env.company.id).lot_stock_id.id, + "default_location_dest_id": self.with_context( + company_id=self.env.company.id).consu_prep_location_id.id, } def _get_consumption_prep_return_picking_type_values(self): return { "warehouse_id": self.id, "code": "internal", - "default_location_src_id": self.consu_prep_location_id.id, - "default_location_dest_id": self.lot_stock_id.id, + "default_location_src_id": self.with_context( + company_id=self.env.company.id).consu_prep_location_id.id, + "default_location_dest_id": self.with_context( + company_id=self.env.company.id).lot_stock_id.id, } def _create_consumption_prep_sequence(self): From 247355c2a06347b6788397a752ec9acef44aa478 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:41:14 +0100 Subject: [PATCH 08/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 61 ++++++++++------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index eca38ffb..33b75ffc 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -14,11 +14,9 @@ class Warehouse(models.Model): _inherit = "stock.warehouse" def _get_default_consumption_location_id(self): - property_stock_production = self.env['ir.property'].sudo().search( - [('name', '=', 'property_stock_production'), - ('company_id', '=', self.env.company.id)]) - location_id = property_stock_production.value_reference.split(',')[-1] - return location_id + return self.env.ref( + "stock.location_production", raise_if_not_found=False + ).id consu_steps = fields.Selection( [(ONE_STEP_KEY, ONE_STEP_DESCRIPTION)], default=ONE_STEP_KEY @@ -32,23 +30,27 @@ def _has_one_step_consumption(self): "Consumption Location", domain=[("usage", "=", "production")], ondelete="restrict", - default=_get_default_consumption_location_id, + default=_get_default_consumption_location_id, check_company=True ) consu_type_id = fields.Many2one( - "stock.picking.type", "Consumption Picking Type", ondelete="restrict" + "stock.picking.type", "Consumption Picking Type", ondelete="restrict", + check_company=True ) consu_return_type_id = fields.Many2one( - "stock.picking.type", "Consumption Return Picking Type", ondelete="restrict" + "stock.picking.type", "Consumption Return Picking Type", ondelete="restrict", + check_company=True ) consu_route_id = fields.Many2one( - "stock.location.route", "Consumption Route", ondelete="restrict" + "stock.location.route", "Consumption Route", ondelete="restrict", + check_company=True ) consu_mto_pull_id = fields.Many2one( - "stock.rule", "Consumption MTO Pull", ondelete="restrict" + "stock.rule", "Consumption MTO Pull", ondelete="restrict", + check_company=True ) @api.model @@ -105,7 +107,7 @@ def _get_consumption_picking_type_create_values(self): vals.update( { "name": _("Consumption"), - "company_id": self.env.company.id, + "company_id": self.company_id.id, "use_create_lots": True, "sequence_code": "CO", "use_existing_lots": True, @@ -122,7 +124,7 @@ def _get_consumption_return_picking_type_create_values(self): "name": _("Consumption Return"), "use_create_lots": False, "use_existing_lots": False, - "company_id": self.env.company.id, + "company_id": self.company_id.id, "sequence_code": "COR", "sequence": 101, "sequence_id": self._create_consumption_return_sequence().id, @@ -150,14 +152,11 @@ def _get_consumption_return_picking_type_values(self): return { "warehouse_id": self.id, "code": "consumption_return", - "default_location_src_id": self.with_context( - company_id=self.env.company.id).consu_location_id.id, + "default_location_src_id": self.consu_location_id.id, "default_location_dest_id": ( - self.with_context( - company_id=self.env.company.id).lot_stock_id.id + self.lot_stock_id.id if self._has_one_step_consumption() - else self.with_context( - company_id=self.env.company.id).consu_prep_location_id.id + else self.consu_prep_location_id.id ), } @@ -174,7 +173,7 @@ def _get_consumption_sequence_values(self): "name": "{}: Consumption".format(self.name), "prefix": "{}/CO/".format(self.code), "padding": 5, - "company_id": self.env.company.id, + "company_id": self.company_id.id, } def _get_consumption_return_sequence_values(self): @@ -182,7 +181,7 @@ def _get_consumption_return_sequence_values(self): "name": "{}: Consumption Return".format(self.name), "prefix": "{}/COR/".format(self.code), "padding": 5, - "company_id": self.env.company.id, + "company_id": self.company_id.id, } def _create_or_update_consumption_route(self): @@ -209,7 +208,7 @@ def _get_consumption_route_values(self): description=self._get_consumption_route_description(), ), "active": True, - "company_id": self.env.company.id, + "company_id": self.company_id.id, "product_categ_selectable": True, "warehouse_selectable": True, "product_selectable": False, @@ -248,7 +247,7 @@ def _get_consumption_pull_values(self): "picking_type_id": self.consu_type_id.id, "action": "pull", "active": True, - "company_id": self.env.company.id, + "company_id": self.company_id.id, "sequence": 1, "propagate_cancel": True, "procure_method": procure_method, @@ -279,7 +278,7 @@ def _get_consumption_mto_pull_vals(self): "picking_type_id": self.consu_type_id.id, "action": "pull", "active": True, - "company_id": self.env.company.id, + "company_id": self.company_id.id, "sequence": 1, "propagate_cancel": True, "procure_method": "make_to_order", @@ -332,7 +331,7 @@ def _update_consumption_route(self): def _update_consumption_prep_pull(self): existing_pull = self.consu_route_id.with_context( - active_test=False,company_id = self.env.company.id + active_test=False ).rule_ids.filtered(lambda p: p.location_id == self.consu_prep_location_id) pull_required = self._has_two_steps_consumption() @@ -358,7 +357,7 @@ def _get_consumption_prep_pull_values(self): "picking_type_id": self.consu_prep_type_id.id, "action": "pull", "active": True, - "company_id": self.env.company.id, + "company_id": self.company_id.id, "sequence": 2, "propagate_cancel": True, "procure_method": "make_to_stock", @@ -447,20 +446,16 @@ def _get_consumption_prep_picking_type_values(self): return { "warehouse_id": self.id, "code": "internal", - "default_location_src_id": self.with_context( - company_id=self.env.company.id).lot_stock_id.id, - "default_location_dest_id": self.with_context( - company_id=self.env.company.id).consu_prep_location_id.id, + "default_location_src_id": self.lot_stock_id.id, + "default_location_dest_id": self.consu_prep_location_id.id, } def _get_consumption_prep_return_picking_type_values(self): return { "warehouse_id": self.id, "code": "internal", - "default_location_src_id": self.with_context( - company_id=self.env.company.id).consu_prep_location_id.id, - "default_location_dest_id": self.with_context( - company_id=self.env.company.id).lot_stock_id.id, + "default_location_src_id": self.consu_prep_location_id.id, + "default_location_dest_id": self.lot_stock_id.id, } def _create_consumption_prep_sequence(self): From 2ce99fb27ee33acb150838e9f586f034c5279f3e Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 20:45:47 +0100 Subject: [PATCH 09/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 33b75ffc..c3bda7f8 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -14,9 +14,11 @@ class Warehouse(models.Model): _inherit = "stock.warehouse" def _get_default_consumption_location_id(self): - return self.env.ref( - "stock.location_production", raise_if_not_found=False - ).id + property_stock_production = self.env['ir.property'].sudo().search( + [('name', '=', 'property_stock_production'), + ('company_id', '=', self.env.company.id)]) + location_id = property_stock_production.value_reference.split(',')[-1] + return location_id consu_steps = fields.Selection( [(ONE_STEP_KEY, ONE_STEP_DESCRIPTION)], default=ONE_STEP_KEY From 4f4b5512f75683ed7e2e267bcfba6449e593c09c Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Wed, 30 Oct 2024 21:00:24 +0100 Subject: [PATCH 10/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index c3bda7f8..6b1ec1a6 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -81,6 +81,7 @@ def write(self, vals): return True def _create_or_update_consumption_picking_types(self): + self = self.with_company(self.company_id) if self.consu_type_id: self._update_consumption_picking_types() else: @@ -187,6 +188,7 @@ def _get_consumption_return_sequence_values(self): } def _create_or_update_consumption_route(self): + self = self.with_company(self.company_id) if self.consu_route_id: self._update_consumption_route() else: From a57ad79a6382a490e02c57baa61ea8779dd20cbb Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:17:37 +0100 Subject: [PATCH 11/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/init_hook.py | 4 ++++ project_material/models/stock_warehouse.py | 15 +-------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/project_material/init_hook.py b/project_material/init_hook.py index fff20738..7d274cdd 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -12,5 +12,9 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): warehouses = env["stock.warehouse"].search([]) for warehouse in warehouses: + location_id = env["ir.property"].with_company( + warehouse.company_id.id)._get( + "property_stock_production", "product.template") + warehouse.consu_location_id = location_id.id warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 6b1ec1a6..413d608a 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -13,13 +13,6 @@ class Warehouse(models.Model): _inherit = "stock.warehouse" - def _get_default_consumption_location_id(self): - property_stock_production = self.env['ir.property'].sudo().search( - [('name', '=', 'property_stock_production'), - ('company_id', '=', self.env.company.id)]) - location_id = property_stock_production.value_reference.split(',')[-1] - return location_id - consu_steps = fields.Selection( [(ONE_STEP_KEY, ONE_STEP_DESCRIPTION)], default=ONE_STEP_KEY ) @@ -32,27 +25,22 @@ def _has_one_step_consumption(self): "Consumption Location", domain=[("usage", "=", "production")], ondelete="restrict", - default=_get_default_consumption_location_id, check_company=True ) consu_type_id = fields.Many2one( "stock.picking.type", "Consumption Picking Type", ondelete="restrict", - check_company=True ) consu_return_type_id = fields.Many2one( "stock.picking.type", "Consumption Return Picking Type", ondelete="restrict", - check_company=True ) consu_route_id = fields.Many2one( "stock.location.route", "Consumption Route", ondelete="restrict", - check_company=True ) consu_mto_pull_id = fields.Many2one( "stock.rule", "Consumption MTO Pull", ondelete="restrict", - check_company=True ) @api.model @@ -90,7 +78,6 @@ def _create_or_update_consumption_picking_types(self): def _create_consumption_picking_types(self): vals = self._get_consumption_picking_type_create_values() self.consu_type_id = self.env["stock.picking.type"].create(vals) - vals = self._get_consumption_return_picking_type_create_values() self.consu_return_type_id = self.env["stock.picking.type"].create(vals) @@ -148,7 +135,7 @@ def _get_consumption_picking_type_values(self): if self._has_one_step_consumption() else self.consu_prep_location_id.id ), - "default_location_dest_id": self.consu_location_id.id, + "default_location_dest_id": self.with_company(self.company_id).consu_location_id.id, } def _get_consumption_return_picking_type_values(self): From ec8352b09409a27dd88113f9d3fd59bd0f211dab Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:23:50 +0100 Subject: [PATCH 12/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/tests/test_consumption_route.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index db995743..1660bcac 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -17,10 +17,10 @@ def setUpClass(cls): cls.new_warehouse = cls.env["stock.warehouse"].search( [("company_id", "=", cls.new_company.id)], limit=1 ) - property_stock_production = cls.env['ir.property'].sudo().search( - [('name', '=', 'property_stock_production'), - ('company_id', '=', cls.env.user.company_id.id)]) - cls.location_id = property_stock_production.value_reference.split(',')[-1] + cls.location_id = cls.env["ir.property"].with_company( + cls.new_warehouse.company_id.id)._get( + "property_stock_production", "product.template") + class TestConsumptionStep(ConsumptionRouteCase): From 72eecf55378b450bf050e827e1656edbac53eaca Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:31:00 +0100 Subject: [PATCH 13/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/init_hook.py | 5 +---- project_material/models/stock_warehouse.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/project_material/init_hook.py b/project_material/init_hook.py index 7d274cdd..3881ce8f 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -12,9 +12,6 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): warehouses = env["stock.warehouse"].search([]) for warehouse in warehouses: - location_id = env["ir.property"].with_company( - warehouse.company_id.id)._get( - "property_stock_production", "product.template") - warehouse.consu_location_id = location_id.id + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 413d608a..46a1a01c 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -50,6 +50,8 @@ def create(self, vals): Use sudo to prevent errors related to access rights. """ warehouse = super().create(vals) + + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_consumption_picking_types() warehouse.sudo()._create_consumption_route() warehouse.sudo()._create_consumption_mto_pull() @@ -63,10 +65,18 @@ def write(self, vals): super().write(vals) if "consu_steps" in vals: for warehouse in self: + warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_or_update_consumption_picking_types() warehouse.sudo()._create_or_update_consumption_route() warehouse.sudo()._create_or_update_consumption_mto_pull() return True + + @api.model + def _get_consu_location_id(self): + location_id = self.env["ir.property"].with_company( + self.company_id.id)._get( + "property_stock_production","product.template").id + return location_id def _create_or_update_consumption_picking_types(self): self = self.with_company(self.company_id) From 79c6557e70c06dd662158ab581e10784ffea9c99 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:34:12 +0100 Subject: [PATCH 14/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 5 ++--- project_material/tests/test_consumption_route.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 46a1a01c..7b20257e 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -50,7 +50,6 @@ def create(self, vals): Use sudo to prevent errors related to access rights. """ warehouse = super().create(vals) - warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_consumption_picking_types() warehouse.sudo()._create_consumption_route() @@ -70,12 +69,12 @@ def write(self, vals): warehouse.sudo()._create_or_update_consumption_route() warehouse.sudo()._create_or_update_consumption_mto_pull() return True - + @api.model def _get_consu_location_id(self): location_id = self.env["ir.property"].with_company( self.company_id.id)._get( - "property_stock_production","product.template").id + "property_stock_production", "product.template").id return location_id def _create_or_update_consumption_picking_types(self): diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index 1660bcac..2699403e 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -22,7 +22,6 @@ def setUpClass(cls): "property_stock_production", "product.template") - class TestConsumptionStep(ConsumptionRouteCase): def test_default_consumption_location(self): assert self.new_warehouse.consu_location_id.id == self.location_id From 8c38261a223185612014090f80ef5a18850eaa15 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:35:01 +0100 Subject: [PATCH 15/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/tests/test_consumption_route.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index 2699403e..89a4e360 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -19,7 +19,7 @@ def setUpClass(cls): ) cls.location_id = cls.env["ir.property"].with_company( cls.new_warehouse.company_id.id)._get( - "property_stock_production", "product.template") + "property_stock_production", "product.template").id class TestConsumptionStep(ConsumptionRouteCase): From ca9260a161462066c32fb93a8950309035179f1a Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 04:55:33 +0100 Subject: [PATCH 16/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/i18n/fr.po | 7 +++++++ project_material/models/stock_warehouse.py | 8 ++++++++ project_material/tests/test_consumption_route.py | 11 +++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/project_material/i18n/fr.po b/project_material/i18n/fr.po index b1e62497..75997cae 100644 --- a/project_material/i18n/fr.po +++ b/project_material/i18n/fr.po @@ -477,3 +477,10 @@ msgid "" msgstr "" "Vous ne pouvez pas modifier l'article ou la tâche sur la ligne de matériel " "{line} car elle est liée à un (des) mouvement(s) de stock au statut terminé." + + +#. module: project_material +#: code:addons/project_material/models/stock_warehouse.py:251 +#, python-format +msgid "You need to have a property_stock_production for product.template. Please contact your administrator or manager." +msgstr "Vous devez définir une property_stock_production pour product.template. Veuillez contacter votre administrateur ou manager." diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 7b20257e..82d8e019 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -2,6 +2,7 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError ONE_STEP_KEY = "one_step" @@ -75,6 +76,13 @@ def _get_consu_location_id(self): location_id = self.env["ir.property"].with_company( self.company_id.id)._get( "property_stock_production", "product.template").id + if not location_id: + raise ValidationError( + _( + "You need to have a property_stock_production for product.template." + " Please contact your administrator or manager." + ) + ) return location_id def _create_or_update_consumption_picking_types(self): diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index 89a4e360..89f0fdbb 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -17,14 +17,17 @@ def setUpClass(cls): cls.new_warehouse = cls.env["stock.warehouse"].search( [("company_id", "=", cls.new_company.id)], limit=1 ) - cls.location_id = cls.env["ir.property"].with_company( - cls.new_warehouse.company_id.id)._get( - "property_stock_production", "product.template").id class TestConsumptionStep(ConsumptionRouteCase): + def test_property_stock_production_exist(self): + property = self.env["ir.property"].with_company(self.company_id.id)._get( + "property_stock_production", "product.template") + self.assertTrue(property.exists()) + def test_default_consumption_location(self): - assert self.new_warehouse.consu_location_id.id == self.location_id + location_id = self.new_warehouse._get_consu_location_id() + assert self.new_warehouse.consu_location_id.id == location_id def test_main_warehouse_has_consumption_route(self): assert self.main_warehouse.consu_route_id From 230aa7a63240503aedd89ff7331e30e010b6f857 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 05:01:34 +0100 Subject: [PATCH 17/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/i18n/fr.po | 2 +- project_material/tests/test_consumption_route.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project_material/i18n/fr.po b/project_material/i18n/fr.po index 75997cae..8f938176 100644 --- a/project_material/i18n/fr.po +++ b/project_material/i18n/fr.po @@ -480,7 +480,7 @@ msgstr "" #. module: project_material -#: code:addons/project_material/models/stock_warehouse.py:251 +#: code:addons/project_material/models/stock_warehouse.py:73 #, python-format msgid "You need to have a property_stock_production for product.template. Please contact your administrator or manager." msgstr "Vous devez définir une property_stock_production pour product.template. Veuillez contacter votre administrateur ou manager." diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index 89f0fdbb..264a86ad 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -20,8 +20,8 @@ def setUpClass(cls): class TestConsumptionStep(ConsumptionRouteCase): - def test_property_stock_production_exist(self): - property = self.env["ir.property"].with_company(self.company_id.id)._get( + def test_property_stock_production_if_exists(self): + property = self.env["ir.property"].with_company(self.new_company.id)._get( "property_stock_production", "product.template") self.assertTrue(property.exists()) From 8569d015e556f255caa51e1c2615d27e90fb9aa1 Mon Sep 17 00:00:00 2001 From: Abdellatif Benzbiria Date: Fri, 1 Nov 2024 05:23:02 +0100 Subject: [PATCH 18/21] TA#70584 [14.0][DEL] stock_location_production --- project_material/models/stock_warehouse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 82d8e019..628a1983 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -86,7 +86,6 @@ def _get_consu_location_id(self): return location_id def _create_or_update_consumption_picking_types(self): - self = self.with_company(self.company_id) if self.consu_type_id: self._update_consumption_picking_types() else: From 0a7df5a0a94ddcb75b4b306fcb644a1dd780d0f6 Mon Sep 17 00:00:00 2001 From: majouda Date: Sun, 10 Nov 2024 21:03:17 -0500 Subject: [PATCH 19/21] TA#70584 [14.0][FIX] project_material: Multico Issues --- project_material/__manifest__.py | 2 +- project_material/init_hook.py | 1 - project_material/models/stock_warehouse.py | 61 +++++++++++-------- .../tests/test_consumption_route.py | 14 ++--- 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/project_material/__manifest__.py b/project_material/__manifest__.py index 191c4df9..e5322917 100644 --- a/project_material/__manifest__.py +++ b/project_material/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Project Material", - "version": "14.0.1.2.1", + "version": "14.0.1.3.0", "author": "Numigi", "maintainer": "Numigi", "website": "https://bit.ly/numigi-com", diff --git a/project_material/init_hook.py b/project_material/init_hook.py index 3881ce8f..fff20738 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -12,6 +12,5 @@ def post_init_hook(cr, registry): def _setup_warehouses_consumption_routes(env): warehouses = env["stock.warehouse"].search([]) for warehouse in warehouses: - warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 628a1983..9e0adeb8 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -2,7 +2,6 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). from odoo import api, fields, models, _ -from odoo.exceptions import ValidationError ONE_STEP_KEY = "one_step" @@ -24,26 +23,47 @@ def _has_one_step_consumption(self): consu_location_id = fields.Many2one( "stock.location", "Consumption Location", - domain=[("usage", "=", "production")], + domain="[('usage', '=', 'production'), ('company_id', '=', company_id)]", + compute='_compute_consu_location_id', ondelete="restrict", + store=True, + check_company=True, ) consu_type_id = fields.Many2one( - "stock.picking.type", "Consumption Picking Type", ondelete="restrict", + "stock.picking.type", + "Consumption Picking Type", + ondelete="restrict", + check_company=True, ) consu_return_type_id = fields.Many2one( - "stock.picking.type", "Consumption Return Picking Type", ondelete="restrict", + "stock.picking.type", + "Consumption Return Picking Type", + ondelete="restrict", + check_company=True, ) consu_route_id = fields.Many2one( - "stock.location.route", "Consumption Route", ondelete="restrict", + "stock.location.route", + "Consumption Route", + ondelete="restrict", + domain="[('warehouse_selectable', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", + check_company=True, ) consu_mto_pull_id = fields.Many2one( "stock.rule", "Consumption MTO Pull", ondelete="restrict", ) + @api.depends('company_id') + def _compute_consu_location_id(self): + for record in self: + Proprerty = self.env["ir.property"].with_company(record.company_id) + record.consu_location_id = Proprerty._get( + "property_stock_production", "product.template" + ).id + @api.model def create(self, vals): """When creating a new warehouse, create the consumption route. @@ -51,7 +71,6 @@ def create(self, vals): Use sudo to prevent errors related to access rights. """ warehouse = super().create(vals) - warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_consumption_picking_types() warehouse.sudo()._create_consumption_route() warehouse.sudo()._create_consumption_mto_pull() @@ -65,26 +84,11 @@ def write(self, vals): super().write(vals) if "consu_steps" in vals: for warehouse in self: - warehouse.consu_location_id = warehouse._get_consu_location_id() warehouse.sudo()._create_or_update_consumption_picking_types() warehouse.sudo()._create_or_update_consumption_route() warehouse.sudo()._create_or_update_consumption_mto_pull() return True - @api.model - def _get_consu_location_id(self): - location_id = self.env["ir.property"].with_company( - self.company_id.id)._get( - "property_stock_production", "product.template").id - if not location_id: - raise ValidationError( - _( - "You need to have a property_stock_production for product.template." - " Please contact your administrator or manager." - ) - ) - return location_id - def _create_or_update_consumption_picking_types(self): if self.consu_type_id: self._update_consumption_picking_types() @@ -151,7 +155,7 @@ def _get_consumption_picking_type_values(self): if self._has_one_step_consumption() else self.consu_prep_location_id.id ), - "default_location_dest_id": self.with_company(self.company_id).consu_location_id.id, + "default_location_dest_id": self.consu_location_id.id, } def _get_consumption_return_picking_type_values(self): @@ -313,16 +317,23 @@ def _has_two_steps_consumption(self): consu_prep_location_id = fields.Many2one( "stock.location", "Preparation Picking Location", - domain=[("usage", "=", "internal")], + domain="[('usage', '=', 'internal'), ('company_id', '=', company_id)]", ondelete="restrict", + check_company=True, ) consu_prep_type_id = fields.Many2one( - "stock.picking.type", "Preparation Picking Type", ondelete="restrict" + "stock.picking.type", + "Preparation Picking Type", + ondelete="restrict", + check_company=True, ) consu_prep_return_type_id = fields.Many2one( - "stock.picking.type", "Preparation Return Picking Type", ondelete="restrict" + "stock.picking.type", + "Preparation Return Picking Type", + ondelete="restrict", + check_company=True, ) def _create_consumption_route(self): diff --git a/project_material/tests/test_consumption_route.py b/project_material/tests/test_consumption_route.py index 264a86ad..7c87e7b6 100644 --- a/project_material/tests/test_consumption_route.py +++ b/project_material/tests/test_consumption_route.py @@ -20,14 +20,14 @@ def setUpClass(cls): class TestConsumptionStep(ConsumptionRouteCase): - def test_property_stock_production_if_exists(self): - property = self.env["ir.property"].with_company(self.new_company.id)._get( - "property_stock_production", "product.template") - self.assertTrue(property.exists()) - def test_default_consumption_location(self): - location_id = self.new_warehouse._get_consu_location_id() - assert self.new_warehouse.consu_location_id.id == location_id + consu_location_id = ( + self.env["ir.property"] + .with_company(self.new_company.id) + ._get("property_stock_production", "product.template") + ) + self.assertTrue(consu_location_id.exists()) + assert self.new_warehouse.consu_location_id.id == consu_location_id.id def test_main_warehouse_has_consumption_route(self): assert self.main_warehouse.consu_route_id From 940ec2bc722eeaefd40145bdbf24a39e38900bd6 Mon Sep 17 00:00:00 2001 From: majouda Date: Mon, 18 Nov 2024 21:39:41 -0500 Subject: [PATCH 20/21] TA#70584 [14.0][IMP] project_material --- project_material/__manifest__.py | 2 +- project_material/init_hook.py | 1 + project_material/models/stock_move.py | 4 +++ project_material/models/stock_picking.py | 2 ++ project_material/models/stock_rule.py | 31 +++------------------- project_material/models/stock_warehouse.py | 13 +++++---- project_material/views/stock_warehouse.xml | 17 ++++++++---- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/project_material/__manifest__.py b/project_material/__manifest__.py index e5322917..210f24ee 100644 --- a/project_material/__manifest__.py +++ b/project_material/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Project Material", - "version": "14.0.1.3.0", + "version": "14.0.1.4.0", "author": "Numigi", "maintainer": "Numigi", "website": "https://bit.ly/numigi-com", diff --git a/project_material/init_hook.py b/project_material/init_hook.py index fff20738..b5f3c09c 100644 --- a/project_material/init_hook.py +++ b/project_material/init_hook.py @@ -14,3 +14,4 @@ def _setup_warehouses_consumption_routes(env): for warehouse in warehouses: warehouse._create_or_update_consumption_picking_types() warehouse._create_or_update_consumption_route() + warehouse._create_consumption_mto_pull() diff --git a/project_material/models/stock_move.py b/project_material/models/stock_move.py index 9104f7cd..603c7f8c 100644 --- a/project_material/models/stock_move.py +++ b/project_material/models/stock_move.py @@ -12,18 +12,21 @@ class StockMove(models.Model): index=True, ondelete="restrict", readonly=True, + check_company=True, ) project_id = fields.Many2one( related="task_id.project_id", store=True, readonly=True, + check_company=True, ) material_line_id = fields.Many2one( "project.task.material", "Material Line", index=True, ondelete="restrict", + check_company=True, ) def _get_new_picking_values(self): @@ -51,6 +54,7 @@ class StockMoveWithNoAggregation(models.Model): "Destination Material Line", compute="_compute_destination_material_line_id", store=True, + check_company=True, ) @api.depends("material_line_id", "move_dest_ids") diff --git a/project_material/models/stock_picking.py b/project_material/models/stock_picking.py index db3db8ab..4ba2cc90 100644 --- a/project_material/models/stock_picking.py +++ b/project_material/models/stock_picking.py @@ -12,11 +12,13 @@ class StockPicking(models.Model): "project.task", index=True, ondelete="restrict", + check_company=True, ) project_id = fields.Many2one( related="task_id.project_id", store=True, readonly=True, + check_company=True, ) task_readonly = fields.Boolean(compute="_compute_task_modifiers") diff --git a/project_material/models/stock_rule.py b/project_material/models/stock_rule.py index bf01c8fd..1433d453 100644 --- a/project_material/models/stock_rule.py +++ b/project_material/models/stock_rule.py @@ -7,30 +7,7 @@ class StockRule(models.Model): _inherit = "stock.rule" - def _get_stock_move_values( - self, - product_id, - product_qty, - product_uom, - location_id, - name, - origin, - company_id, - values, - ): - result = super()._get_stock_move_values( - product_id, - product_qty, - product_uom, - location_id, - name, - origin, - company_id, - values, - ) - result["material_line_id"] = values.get("material_line_id") - result["task_id"] = values.get("task_id") - if self.group_propagation_option == "propagate": - group_id = values.get("group_id", False) and values["group_id"].id - result["group_id"] = group_id - return result + def _get_custom_move_fields(self): + fields = super(StockRule, self)._get_custom_move_fields() + fields += ["material_line_id", "task_id"] + return fields diff --git a/project_material/models/stock_warehouse.py b/project_material/models/stock_warehouse.py index 9e0adeb8..e508b19c 100644 --- a/project_material/models/stock_warehouse.py +++ b/project_material/models/stock_warehouse.py @@ -32,14 +32,14 @@ def _has_one_step_consumption(self): consu_type_id = fields.Many2one( "stock.picking.type", - "Consumption Picking Type", + "Consumption Type", ondelete="restrict", check_company=True, ) consu_return_type_id = fields.Many2one( "stock.picking.type", - "Consumption Return Picking Type", + "Consumption Return Type", ondelete="restrict", check_company=True, ) @@ -48,12 +48,16 @@ def _has_one_step_consumption(self): "stock.location.route", "Consumption Route", ondelete="restrict", - domain="[('warehouse_selectable', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", + domain="[('company_id', '=', company_id)]", check_company=True, ) consu_mto_pull_id = fields.Many2one( - "stock.rule", "Consumption MTO Pull", ondelete="restrict", + "stock.rule", + "Consumption MTO Pull", + ondelete="restrict", + domain="[('company_id', '=', company_id)]", + check_company=True, ) @api.depends('company_id') @@ -195,7 +199,6 @@ def _get_consumption_return_sequence_values(self): } def _create_or_update_consumption_route(self): - self = self.with_company(self.company_id) if self.consu_route_id: self._update_consumption_route() else: diff --git a/project_material/views/stock_warehouse.xml b/project_material/views/stock_warehouse.xml index 436202c2..bf90445e 100644 --- a/project_material/views/stock_warehouse.xml +++ b/project_material/views/stock_warehouse.xml @@ -8,13 +8,20 @@ - - + + + + + + + + From aec2bd759accb55628c49982ea822822a0defd11 Mon Sep 17 00:00:00 2001 From: majouda Date: Mon, 18 Nov 2024 23:05:12 -0500 Subject: [PATCH 21/21] TA#70584 [14.0][IMP] project_material --- project_material/models/project_task.py | 13 +++++-------- project_material/models/project_task_material.py | 4 ---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/project_material/models/project_task.py b/project_material/models/project_task.py index c9959b75..560b4de2 100644 --- a/project_material/models/project_task.py +++ b/project_material/models/project_task.py @@ -103,25 +103,22 @@ def write(self, vals): def copy(self, vals=None): task = super().copy(vals) - if self.material_line_ids: task.procurement_disabled = True task._copy_material_lines_from(self) - return task - @api.onchange("project_id") - def _onchange_project_enable_procurements(self): - if self.project_id: - self.procurement_disabled = False - def _copy_material_lines_from(self, task): if not self.date_planned: self.date_planned = date(2099, 1, 1) - for line in task.material_line_ids: line.copy({"task_id": self.id}) + @api.onchange("project_id") + def _onchange_project_enable_procurements(self): + if self.project_id: + self.procurement_disabled = False + def _run_procurements(self): for line in self.mapped("material_line_ids"): line._run_procurements() diff --git a/project_material/models/project_task_material.py b/project_material/models/project_task_material.py index ae759856..ce868d1a 100644 --- a/project_material/models/project_task_material.py +++ b/project_material/models/project_task_material.py @@ -318,13 +318,9 @@ def _propagate_planned_date_to_stock_moves(self): moves_to_update = moves.filtered( lambda m: m.state not in ("done", "cancel") ) - delay = moves_to_update.mapped("rule_id.delay") if delay: date_planned = date_planned - timedelta(delay[0]) - - # FIX ME : update date_expected on v12 but use what field on v14 instead - # Maybe `date` ? moves_to_update.with_context(do_not_propagate=True).write( {"date": date_planned} )