From 67022aad7a164a156479ad9c3f62c65e3db2c935 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Tue, 3 Oct 2023 17:47:54 +0200 Subject: [PATCH] [MIG] sale_restricted_qty: Migration to 16.0 --- requirements.txt | 1 - sale_restricted_qty/README.rst | 15 ++++++++----- sale_restricted_qty/__init__.py | 1 - sale_restricted_qty/__manifest__.py | 7 ++---- sale_restricted_qty/hooks.py | 19 ---------------- .../models/product_category.py | 19 +++++++++++++++- sale_restricted_qty/models/sale.py | 22 ++++++++++++++----- sale_restricted_qty/readme/CONTRIBUTORS.rst | 3 +++ .../static/description/index.html | 12 ++++++---- sale_restricted_qty/tests/test_sale.py | 20 ++++------------- .../views/product_product_views.xml | 8 +++++-- 11 files changed, 66 insertions(+), 61 deletions(-) delete mode 100644 sale_restricted_qty/hooks.py diff --git a/requirements.txt b/requirements.txt index 180fc49789b..9cd1629223b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ # generated from manifests external_dependencies -openupgradelib diff --git a/sale_restricted_qty/README.rst b/sale_restricted_qty/README.rst index 4c6e334f40a..fc3b70d22dc 100644 --- a/sale_restricted_qty/README.rst +++ b/sale_restricted_qty/README.rst @@ -7,7 +7,7 @@ Sale order min quantity !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:9d34c5ce0bf0071dd40afa3f708f0f3d3f2098e4ca0d4b26d65bb1a8a40a23e0 + !! source digest: sha256:11c109b03c7404989c3814a5675fcc5ae0cb3088674059b409bc202355156177 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ Sale order min quantity :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github - :target: https://github.com/OCA/sale-workflow/tree/14.0/sale_restricted_qty + :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_restricted_qty :alt: OCA/sale-workflow .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_restricted_qty + :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_restricted_qty :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -64,7 +64,7 @@ Bug Tracker 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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -84,6 +84,9 @@ Contributors * `Ooops `_: * Ashish Hirpara +* `Aion Tech `_: + + * Simone Rubino Maintainers ~~~~~~~~~~~ @@ -106,6 +109,6 @@ Current `maintainer `__: |maintainer-ashishhirapara| -This module is part of the `OCA/sale-workflow `_ project on GitHub. +This module is part of the `OCA/sale-workflow `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_restricted_qty/__init__.py b/sale_restricted_qty/__init__.py index 8e0862219aa..0650744f6bc 100644 --- a/sale_restricted_qty/__init__.py +++ b/sale_restricted_qty/__init__.py @@ -1,2 +1 @@ from . import models -from .hooks import rename_module diff --git a/sale_restricted_qty/__manifest__.py b/sale_restricted_qty/__manifest__.py index 3af3de87e4d..fe43bc7ba30 100644 --- a/sale_restricted_qty/__manifest__.py +++ b/sale_restricted_qty/__manifest__.py @@ -1,18 +1,16 @@ # Copyright 2019 Akretion () +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Sale order min quantity", - "version": "14.0.1.1.1", + "version": "16.0.1.0.0", "category": "Sales Management", "author": "Akretion, Odoo Community Association (OCA)", "contributors": ["Ashish Hirpara"], "maintainers": ["ashishhirapara"], "website": "https://github.com/OCA/sale-workflow", "license": "AGPL-3", - "external_dependencies": { - "python": ["openupgradelib"], - }, "depends": ["sale_management"], "data": [ "views/product_category_views.xml", @@ -20,6 +18,5 @@ "views/product_product_views.xml", "views/sale_views.xml", ], - "pre_init_hook": "rename_module", "installable": True, } diff --git a/sale_restricted_qty/hooks.py b/sale_restricted_qty/hooks.py deleted file mode 100644 index 810cf4053f5..00000000000 --- a/sale_restricted_qty/hooks.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2019 Akretion -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -import logging - -_logger = logging.getLogger(__name__) - -try: - from openupgradelib import openupgrade -except (ImportError, IOError) as err: - _logger.debug(err) - - -def rename_module(cr): - openupgrade.update_module_names( - cr, - [("sale_order_min_qty", "sale_restricted_qty")], - merge_modules=True, - ) diff --git a/sale_restricted_qty/models/product_category.py b/sale_restricted_qty/models/product_category.py index 05815c79a00..b7bb761da88 100644 --- a/sale_restricted_qty/models/product_category.py +++ b/sale_restricted_qty/models/product_category.py @@ -1,13 +1,30 @@ # Copyright 2019 Akretion +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models +from odoo import api, fields, models class ProductCategory(models.Model): _name = "product.category" _inherit = ["product.category", "product.restricted.qty.mixin"] + sale_multiple_qty = fields.Float( + recursive=True, + ) + sale_min_qty = fields.Float( + recursive=True, + ) + force_sale_min_qty = fields.Boolean( + recursive=True, + ) + sale_max_qty = fields.Float( + recursive=True, + ) + force_sale_max_qty = fields.Boolean( + recursive=True, + ) + def _get_sale_restricted_qty(self): res = super()._get_sale_restricted_qty() force_sale_min_qty = False diff --git a/sale_restricted_qty/models/sale.py b/sale_restricted_qty/models/sale.py index 2ae03714d87..7584ca3ac9b 100644 --- a/sale_restricted_qty/models/sale.py +++ b/sale_restricted_qty/models/sale.py @@ -1,4 +1,5 @@ # Copyright 2019 Akretion +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models @@ -56,8 +57,11 @@ def check_constraint_restricted_qty(self): ) for line in line_to_test: invaild_min_lines.append( - _('Product "%s": Min Quantity %s.') - % (line.product_id.name, line.sale_min_qty) + _( + 'Product "%(product)s": Min Quantity %(min_qty)s.', + product=line.product_id.name, + min_qty=line.sale_min_qty, + ) ) if invaild_min_lines: @@ -74,8 +78,11 @@ def check_constraint_restricted_qty(self): ) for line in line_to_test: invaild_max_lines.append( - _('Product "%s": max Quantity %s.') - % (line.product_id.name, line.sale_max_qty) + _( + 'Product "%(product)s": max Quantity %(max_qty)s.', + product=line.product_id.name, + max_qty=line.sale_max_qty, + ) ) if invaild_max_lines: @@ -90,8 +97,11 @@ def check_constraint_restricted_qty(self): line_to_test = self.filtered(lambda sl: sl.is_qty_not_multiple_qty) for line in line_to_test: invaild_multiple_lines.append( - _('Product "%s": multiple Quantity %s.') - % (line.product_id.name, line.sale_multiple_qty) + _( + 'Product "%(product)s": multiple Quantity %(multiple_qty)s.', + product=line.product_id.name, + multiple_qty=line.sale_multiple_qty, + ) ) if invaild_multiple_lines: diff --git a/sale_restricted_qty/readme/CONTRIBUTORS.rst b/sale_restricted_qty/readme/CONTRIBUTORS.rst index ac5fa9a437c..bd4c1d61bef 100644 --- a/sale_restricted_qty/readme/CONTRIBUTORS.rst +++ b/sale_restricted_qty/readme/CONTRIBUTORS.rst @@ -3,3 +3,6 @@ * `Ooops `_: * Ashish Hirpara +* `Aion Tech `_: + + * Simone Rubino diff --git a/sale_restricted_qty/static/description/index.html b/sale_restricted_qty/static/description/index.html index 8cf3afe2190..5b4c747c076 100644 --- a/sale_restricted_qty/static/description/index.html +++ b/sale_restricted_qty/static/description/index.html @@ -367,9 +367,9 @@

Sale order min quantity

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:9d34c5ce0bf0071dd40afa3f708f0f3d3f2098e4ca0d4b26d65bb1a8a40a23e0 +!! source digest: sha256:11c109b03c7404989c3814a5675fcc5ae0cb3088674059b409bc202355156177 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

This module allows to define min, max and multiple order quantity on product. Min and Max order quantity is either required or recommanded. If you check “Force mini/max Qty” on product the min/max qty do not block sale @@ -418,7 +418,7 @@

Bug Tracker

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 to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -437,6 +437,10 @@

Contributors

  • Ashish Hirpara <https://ashish-hirpara.com>
  • +
  • Aion Tech: +
  • @@ -448,7 +452,7 @@

    Maintainers

    promote its widespread use.

    Current maintainer:

    ashishhirapara

    -

    This module is part of the OCA/sale-workflow project on GitHub.

    +

    This module is part of the OCA/sale-workflow project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/sale_restricted_qty/tests/test_sale.py b/sale_restricted_qty/tests/test_sale.py index 425c9c8687d..d1e0aaa8ca8 100644 --- a/sale_restricted_qty/tests/test_sale.py +++ b/sale_restricted_qty/tests/test_sale.py @@ -1,5 +1,6 @@ # Copyright 2019 Akretion # Update (Migration) 2022 Ooops - Ashish Hirpara +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import odoo.tests.common as common @@ -49,31 +50,18 @@ def setUp(self): } ) - def refrech_sale_values(self, sale_order): - sale_order.order_line._compute_sale_restricted_qty() - sale_order.order_line.product_id_change() - sale_order.order_line._compute_is_qty_less_min_qty() - sale_order.order_line._compute_is_qty_bigger_max_qty() - sale_values = sale_order._convert_to_write(sale_order._cache) - return sale_values - def test_check_sale_order_min_qty_required(self): line_values = {"product_id": self.product.id, "product_uom_qty": 5.0} self.product.manual_sale_min_qty = 10 # Create sale order line with Qty less than min Qty with self.assertRaises(ValidationError): - sale_order = self.sale_order_model.new( - {"partner_id": self.partner.id, "order_line": [(0, 0, line_values)]} - ) - sale_values = self.refrech_sale_values(sale_order) - sale_values.update( + self.sale_order_model.create( { - "partner_shipping_id": sale_values["partner_id"], - "partner_invoice_id": sale_values["partner_id"], + "partner_id": self.partner.id, + "order_line": [(0, 0, line_values)], "pricelist_id": 1, } ) - self.sale_order_model.create(sale_values) line_values["product_uom_qty"] = 12.0 # Create sale order line with Qty great then min Qty self.sale_order = self.sale_order_model.create( diff --git a/sale_restricted_qty/views/product_product_views.xml b/sale_restricted_qty/views/product_product_views.xml index 7c6122fb1c7..21dca704f45 100644 --- a/sale_restricted_qty/views/product_product_views.xml +++ b/sale_restricted_qty/views/product_product_views.xml @@ -1,4 +1,8 @@ + @@ -6,7 +10,7 @@ product.product - + - +