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 21, 2024
1 parent c005ba7 commit 9544123
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 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.1",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
18 changes: 17 additions & 1 deletion sale_stock_picking_validation_blocking/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -31,7 +31,7 @@ def setUp(self):
def test_sale_stock_picking_validation_blocked(self):
self.sale_order.action_confirm()
picking = self.sale_order.picking_ids
picking.move_lines.write({"quantity_done": 1})
picking.move_ids.write({"quantity_done": 1})
self.sale_order.action_block_picking_validation()
self.assertFalse(picking.show_validate)
with self.assertRaises(ValidationError):
Expand Down
11 changes: 6 additions & 5 deletions sale_stock_picking_validation_blocking/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@
<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_block_picking_validation" 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="hide_button_block_picking_validation"
/>
<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="hide_button_block_picking_validation or 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="validation_blocked_by_so == False"
groups="stock.group_stock_user"
>
<div
>Warning: The validation of this picking is prevented by sale order <field
Expand Down

0 comments on commit 9544123

Please sign in to comment.