From 5a86a0f8c4b0fd3bfab90e291e2812ba9c7d5d1d Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Mon, 21 Oct 2024 13:22:57 +0300 Subject: [PATCH] [17.0][MIG] sale_stock_picking_validation_blocking: Migration to 17.0 --- .../README.rst | 1 + .../__manifest__.py | 2 +- .../models/sale_order.py | 18 +++++++++++++++++- .../models/stock_picking.py | 3 ++- .../readme/CONTRIBUTORS.md | 1 + .../static/description/index.html | 1 + .../tests/test_sale_stock.py | 2 +- .../views/sale_order.xml | 4 ++-- .../views/stock_picking.xml | 3 ++- 9 files changed, 28 insertions(+), 7 deletions(-) diff --git a/sale_stock_picking_validation_blocking/README.rst b/sale_stock_picking_validation_blocking/README.rst index 7ee0535e4d5..967974682e9 100644 --- a/sale_stock_picking_validation_blocking/README.rst +++ b/sale_stock_picking_validation_blocking/README.rst @@ -78,6 +78,7 @@ Contributors ------------ - Quentin Groulard +- Kevin Khao kevin.khao@gmail.com Maintainers ----------- diff --git a/sale_stock_picking_validation_blocking/__manifest__.py b/sale_stock_picking_validation_blocking/__manifest__.py index 54529b40060..22bd338b710 100644 --- a/sale_stock_picking_validation_blocking/__manifest__.py +++ b/sale_stock_picking_validation_blocking/__manifest__.py @@ -6,7 +6,7 @@ "summary": """ This module adds the opportunity to prevent the validation of delivery order from the SO.""", - "version": "13.0.1.0.1", + "version": "17.0.1.0.1", "license": "AGPL-3", "author": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/sale-workflow", diff --git a/sale_stock_picking_validation_blocking/models/sale_order.py b/sale_stock_picking_validation_blocking/models/sale_order.py index dfc420cb5cd..d3421016a92 100644 --- a/sale_stock_picking_validation_blocking/models/sale_order.py +++ b/sale_stock_picking_validation_blocking/models/sale_order.py @@ -8,8 +8,24 @@ class SaleOrder(models.Model): _inherit = "sale.order" picking_validation_blocked = fields.Boolean( - readonly=True, track_visibility="onchange", string="Delivery Validation Blocked" + readonly=True, tracking=True, string="Delivery Validation Blocked" ) + hide_button_block_picking_validation = fields.Boolean( + "Display the picking validation buttons", + help="Technical field to determine whether the " + "picking validation buttons should be displayed", + compute="_compute_display_button_block_picking_validation", + compute_sudo=True, + ) + + def _compute_display_button_block_picking_validation(self): + for rec in self: + rec.hide_button_block_picking_validation = ( + self.env.user.has_group("sales_team.group_sale_manager") + and rec.state not in ("sale", "done") + or rec.delivery_count == 0 + or rec.picking_validation_blocked is True + ) def action_block_picking_validation(self): self.write({"picking_validation_blocked": True}) diff --git a/sale_stock_picking_validation_blocking/models/stock_picking.py b/sale_stock_picking_validation_blocking/models/stock_picking.py index 70e8f37737c..a9341339349 100644 --- a/sale_stock_picking_validation_blocking/models/stock_picking.py +++ b/sale_stock_picking_validation_blocking/models/stock_picking.py @@ -14,6 +14,7 @@ class StockPicking(models.Model): string="Validation Blocked by SO", ) + # pylint: disable=W8110 @api.depends("state", "is_locked", "validation_blocked_by_so") def _compute_show_validate(self): for picking in self: @@ -28,4 +29,4 @@ def button_validate(self): raise ValidationError( _("Validation is blocked by SO for picking %s" % picking.name) ) - return super(StockPicking, self).button_validate() + return super().button_validate() diff --git a/sale_stock_picking_validation_blocking/readme/CONTRIBUTORS.md b/sale_stock_picking_validation_blocking/readme/CONTRIBUTORS.md index 01f3219a114..c7e5ddeffbb 100644 --- a/sale_stock_picking_validation_blocking/readme/CONTRIBUTORS.md +++ b/sale_stock_picking_validation_blocking/readme/CONTRIBUTORS.md @@ -1 +1,2 @@ - Quentin Groulard \<\> +- Kevin Khao diff --git a/sale_stock_picking_validation_blocking/static/description/index.html b/sale_stock_picking_validation_blocking/static/description/index.html index 8b81106f1b0..968fa91b1ad 100644 --- a/sale_stock_picking_validation_blocking/static/description/index.html +++ b/sale_stock_picking_validation_blocking/static/description/index.html @@ -425,6 +425,7 @@

Authors

Contributors

diff --git a/sale_stock_picking_validation_blocking/tests/test_sale_stock.py b/sale_stock_picking_validation_blocking/tests/test_sale_stock.py index ec4bbfe108c..22db6531849 100644 --- a/sale_stock_picking_validation_blocking/tests/test_sale_stock.py +++ b/sale_stock_picking_validation_blocking/tests/test_sale_stock.py @@ -7,7 +7,7 @@ class TestSaleStock(TransactionCase): def setUp(self): - super(TestSaleStock, self).setUp() + super().setUp() partner = self.env.ref("base.res_partner_1") product = self.env.ref("product.product_delivery_01") self.sale_order = self.env["sale.order"].create( diff --git a/sale_stock_picking_validation_blocking/views/sale_order.xml b/sale_stock_picking_validation_blocking/views/sale_order.xml index 3beb89a75ba..d820ef54030 100644 --- a/sale_stock_picking_validation_blocking/views/sale_order.xml +++ b/sale_stock_picking_validation_blocking/views/sale_order.xml @@ -15,14 +15,14 @@ type="object" string="Block Delivery Validation" groups="sales_team.group_sale_manager" - attrs="{'invisible': ['|', '|', ('state', 'not in', ('sale', 'done')), ('delivery_count', '=', 0), ('picking_validation_blocked', '=', True)]}" + invisible="hide_button_block_picking_validation" /> diff --git a/sale_stock_picking_validation_blocking/views/stock_picking.xml b/sale_stock_picking_validation_blocking/views/stock_picking.xml index a8312e7280b..c56af8c386a 100644 --- a/sale_stock_picking_validation_blocking/views/stock_picking.xml +++ b/sale_stock_picking_validation_blocking/views/stock_picking.xml @@ -14,7 +14,8 @@