From 38ed109bcf06c86fb48c731634989799daf9bea5 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 1 Feb 2023 16:26:41 +0100 Subject: [PATCH] [MIG] stock_orderpoint_generator: Migration to 15.0 TT36996 --- stock_orderpoint_generator/README.rst | 16 ++++----- stock_orderpoint_generator/__manifest__.py | 7 ++-- .../models/orderpoint_template.py | 24 +++++++------ stock_orderpoint_generator/models/product.py | 3 +- .../security/ir.model.access.csv | 1 + .../static/description/index.html | 10 +++--- .../tests/test_orderpoint_generator.py | 26 +++++++------- .../views/orderpoint_template_views.xml | 7 +--- .../wizard/orderpoint_generator_view.xml | 34 +++++++++---------- 9 files changed, 62 insertions(+), 66 deletions(-) diff --git a/stock_orderpoint_generator/README.rst b/stock_orderpoint_generator/README.rst index fbb92b42c52e..375015bad6a9 100644 --- a/stock_orderpoint_generator/README.rst +++ b/stock_orderpoint_generator/README.rst @@ -13,14 +13,14 @@ Order point generator .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_orderpoint_generator - :alt: OCA/stock-logistics-warehouse +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github + :target: https://github.com/OCA/sale-promotion/tree/15.0/stock_orderpoint_generator + :alt: OCA/sale-promotion .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_orderpoint_generator + :target: https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-stock_orderpoint_generator :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/153/13.0 + :target: https://runbot.odoo-community.org/runbot/296/15.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -77,10 +77,10 @@ feature on products that have Automatic Reordering Rules Templates. Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -119,6 +119,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. +This module is part of the `OCA/sale-promotion `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_orderpoint_generator/__manifest__.py b/stock_orderpoint_generator/__manifest__.py index f10ecce00d6b..3ffb65d2325d 100644 --- a/stock_orderpoint_generator/__manifest__.py +++ b/stock_orderpoint_generator/__manifest__.py @@ -5,12 +5,12 @@ { "name": "Order point generator", "summary": "Mass configuration of stock order points", - "version": "13.0.2.0.0", - "author": "Camptocamp, " "Tecnativa, " "Odoo Community Association (OCA)", + "version": "15.0.1.0.0", + "author": "Camptocamp, Tecnativa, Odoo Community Association (OCA)", "category": "Warehouse", "license": "AGPL-3", "website": "https://github.com/OCA/stock-logistics-warehouse", - "depends": ["stock"], + "depends": ["sale_stock"], "data": [ "views/orderpoint_template_views.xml", "wizard/orderpoint_generator_view.xml", @@ -18,5 +18,4 @@ "security/ir.model.access.csv", ], "installable": True, - "auto_install": False, } diff --git a/stock_orderpoint_generator/models/orderpoint_template.py b/stock_orderpoint_generator/models/orderpoint_template.py index cc0f0d753937..eec759661449 100644 --- a/stock_orderpoint_generator/models/orderpoint_template.py +++ b/stock_orderpoint_generator/models/orderpoint_template.py @@ -2,8 +2,6 @@ # Copyright 2019 David Vidal - Tecnativa # Copyright 2020 Víctor Martínez - Tecnativa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - from statistics import mean, median_high from odoo import api, fields, models @@ -36,7 +34,7 @@ class OrderpointTemplate(models.Model): auto_min_qty = fields.Boolean( string="Auto Minimum", - help="Auto compute minimum quantity " "per product for a given a date range", + help="Auto compute minimum quantity per product for a given a date range", ) auto_min_date_start = fields.Datetime() auto_min_date_end = fields.Datetime() @@ -53,7 +51,7 @@ class OrderpointTemplate(models.Model): ) auto_max_qty = fields.Boolean( string="Auto Maximum", - help="Auto compute maximum quantity " "per product for a given a date range", + help="Auto compute maximum quantity per product for a given a date range", ) auto_max_qty_criteria = fields.Selection( selection=[ @@ -98,12 +96,15 @@ def _template_fields_to_discard(self): "auto_max_qty", ] - def _disable_old_instances(self, products): + def _remove_old_instances(self, products): """Clean old instance by setting those inactives""" - orderpoints = self.env["stock.warehouse.orderpoint"].search( - [("product_id", "in", products.ids)] - ) - orderpoints.write({"active": False}) + self.env["stock.warehouse.orderpoint"].search( + [ + ("product_id", "in", products.ids), + ("location_id", "=", self.location_id.id), + ("company_id", "=", self.company_id.id), + ] + ).unlink() @api.model def _get_criteria_methods(self): @@ -184,8 +185,9 @@ def create_orderpoints(self, products): """Create orderpoint for *products* based on these templates. :type products: recordset of products """ - self._disable_old_instances(products) - self._create_instances(products) + for order_point in self: + order_point._remove_old_instances(products) + order_point._create_instances(products) def create_auto_orderpoints(self): for template in self: diff --git a/stock_orderpoint_generator/models/product.py b/stock_orderpoint_generator/models/product.py index 981654a0ba60..c9d7928ac58d 100644 --- a/stock_orderpoint_generator/models/product.py +++ b/stock_orderpoint_generator/models/product.py @@ -31,8 +31,7 @@ def create(self, vals): def write(self, vals): result = super().write(vals) if vals.get("auto_orderpoint_template_ids"): - orderpoint_templates = self.mapped("auto_orderpoint_template_ids") - orderpoint_templates.create_orderpoints(self) + self.auto_orderpoint_template_ids.create_orderpoints(self) return result def _get_stock_move_domain(self, domain_move=False, from_date=False, to_date=False): diff --git a/stock_orderpoint_generator/security/ir.model.access.csv b/stock_orderpoint_generator/security/ir.model.access.csv index d6a748cc256b..7583f98b237b 100644 --- a/stock_orderpoint_generator/security/ir.model.access.csv +++ b/stock_orderpoint_generator/security/ir.model.access.csv @@ -1,2 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_stock_warehouse_orderpoint_template,stock.warehouse.manage,model_stock_warehouse_orderpoint_template,stock.group_stock_manager,1,1,1,1 +stock_orderpoint_generator.access_stock_warehouse_orderpoint_generator,access_stock_warehouse_orderpoint_generator,stock_orderpoint_generator.model_stock_warehouse_orderpoint_generator,stock.group_stock_manager,1,1,1,1 diff --git a/stock_orderpoint_generator/static/description/index.html b/stock_orderpoint_generator/static/description/index.html index bc83f7682a74..003f4d14e54a 100644 --- a/stock_orderpoint_generator/static/description/index.html +++ b/stock_orderpoint_generator/static/description/index.html @@ -3,7 +3,7 @@ - + Order point generator