Skip to content

Commit

Permalink
[17.0][MIG] sale_stock_picking_validation_blocking: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Oct 22, 2024
1 parent c005ba7 commit 6bd7915
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions sale_stock_picking_validation_blocking/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Contributors
------------

- Quentin Groulard <[email protected]>
- Kevin Khao [email protected]

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion sale_stock_picking_validation_blocking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
20 changes: 18 additions & 2 deletions sale_stock_picking_validation_blocking/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


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_picking_validation_blocked = fields.Boolean(
"Display the picking validation buttons",
help="Technical field to determine whether the "
"picking validation buttons should be displayed",
compute="_compute_hide_picking_validation_blocked",
compute_sudo=True,
)

@api.depends("picking_validation_blocked", "state", "delivery_count")
def _compute_hide_picking_validation_blocked(self):
for rec in self:
rec.hide_button_picking_validation_blocked = (
rec.state != "sale"
or not self.env.user.has_group("sales_team.group_sale_manager")
or rec.delivery_count == 0
)

def action_block_picking_validation(self):
self.write({"picking_validation_blocked": True})
Expand Down
12 changes: 2 additions & 10 deletions sale_stock_picking_validation_blocking/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import _, fields, models
from odoo.exceptions import ValidationError


Expand All @@ -14,18 +14,10 @@ class StockPicking(models.Model):
string="Validation Blocked by SO",
)

@api.depends("state", "is_locked", "validation_blocked_by_so")
def _compute_show_validate(self):
for picking in self:
if picking.validation_blocked_by_so:
picking.show_validate = False
else:
super(StockPicking, picking)._compute_show_validate()

def button_validate(self):
for picking in self:
if picking.validation_blocked_by_so:
raise ValidationError(
_("Validation is blocked by SO for picking %s" % picking.name)
)
return super(StockPicking, self).button_validate()
return super().button_validate()
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Quentin Groulard \<<[email protected]>\>
- Kevin Khao <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Quentin Groulard &lt;<a class="reference external" href="mailto:quentin.groulard&#64;acsone.eu">quentin.groulard&#64;acsone.eu</a>&gt;</li>
<li>Kevin Khao <a class="reference external" href="mailto:kevin.khao&#64;gmail.com">kevin.khao&#64;gmail.com</a></li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
19 changes: 11 additions & 8 deletions sale_stock_picking_validation_blocking/tests/test_sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@


class TestSaleStock(TransactionCase):
def setUp(self):
super(TestSaleStock, self).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(
@classmethod
def setUpClass(cls):
super().setUpClass()
partner = cls.env.ref("base.res_partner_1")
product = cls.env.ref("product.product_delivery_01")
cls.sale_order = cls.env["sale.order"].create(
{
"partner_id": partner.id,
"order_line": [
Expand All @@ -29,13 +30,15 @@ def setUp(self):
)

def test_sale_stock_picking_validation_blocked(self):
self.assertTrue(self.sale_order.hide_button_picking_validation_blocked)
self.sale_order.action_confirm()
self.assertFalse(self.sale_order.hide_button_picking_validation_blocked)
picking = self.sale_order.picking_ids
picking.move_lines.write({"quantity_done": 1})
picking.move_ids.write({"quantity": 1})
self.assertFalse(self.sale_order.picking_validation_blocked)
self.sale_order.action_block_picking_validation()
self.assertFalse(picking.show_validate)
self.assertTrue(self.sale_order.picking_validation_blocked)
with self.assertRaises(ValidationError):
picking.button_validate()
self.sale_order.action_unblock_picking_validation()
self.assertTrue(picking.show_validate)
picking.button_validate()
13 changes: 8 additions & 5 deletions sale_stock_picking_validation_blocking/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
<!-- Copyright 2020 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="sale_order_form_view">
<field
name="name"
>sale.order.form (in sale_stock_picking_validation_blocking)</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale_stock.view_order_form_inherit_sale_stock" />
<field name="arch" type="xml">
<field name="warehouse_id" position="before">
<field name="picking_validation_blocked" />
<field name="hide_button_picking_validation_blocked" invisible="True" />
</field>
<button name="action_draft" position="after">
<button
name="action_block_picking_validation"
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="picking_validation_blocked or hide_button_picking_validation_blocked"
/>
<button
name="action_unblock_picking_validation"
type="object"
string="Unblock Delivery Validation"
groups="sales_team.group_sale_manager"
attrs="{'invisible': ['|', '|', ('state', 'not in', ('sale', 'done')), ('delivery_count', '=', 0), ('picking_validation_blocked', '!=', True)]}"
invisible="not picking_validation_blocked or hide_button_picking_validation_blocked"
/>
</button>
<field name="warehouse_id" position="before">
<field name="picking_validation_blocked" />
</field>
</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<div
class="alert alert-danger text-center o_form_header"
role="alert"
attrs="{'invisible': [('validation_blocked_by_so', '=', False)]}"
invisible="not validation_blocked_by_so"
groups="stock.group_stock_user"
>
<div
>Warning: The validation of this picking is prevented by sale order <field
Expand Down

0 comments on commit 6bd7915

Please sign in to comment.