Skip to content

Commit

Permalink
[MIG] stock_exception: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mav-adhoc committed Jul 4, 2024
1 parent 2aef72f commit 8bd838d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 11 deletions.
3 changes: 2 additions & 1 deletion stock_exception/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Exception",
"summary": "Custom exceptions on stock picking",
"version": "16.0.1.0.0",
"version": "16.0.1.1.0",
"category": "Generic Modules/Warehouse Management",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
Expand All @@ -15,6 +15,7 @@
"data/stock_exception_data.xml",
"wizard/stock_exception_confirm_view.xml",
"views/stock_view.xml",
"views/exception_rule_views.xml",
],
"installable": True,
}
4 changes: 2 additions & 2 deletions stock_exception/data/stock_exception_data.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<odoo noupdate="1">
<!-- Test Stock Exceptions Scheduler-->
<record model="ir.cron" forcecreate="True" id="ir_cron_test_stock_picking_except">
<!-- <record model="ir.cron" forcecreate="True" id="ir_cron_test_stock_picking_except">
<field name="name">Stock: Test Draft Pickings Exception</field>
<field name="model_id" ref="stock.model_stock_picking" />
<field name="state">code</field>
Expand All @@ -11,7 +11,7 @@
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="active" eval="False" />
</record>
</record> -->
<record id="sp_excep_no_partner" model="exception.rule">
<field name="name">No Partner</field>
<field name="description">No Partner</field>
Expand Down
2 changes: 2 additions & 0 deletions stock_exception/models/exception_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ class ExceptionRule(models.Model):
],
ondelete={"stock.picking": "cascade", "stock.move": "cascade"},
)
check_on_validate = fields.Boolean(default=False)
check_on_confirm = fields.Boolean(default=False)
57 changes: 50 additions & 7 deletions stock_exception/models/stock.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Copyright 2021 Ecosoft Co., Ltd (https://ecosoft.co.th)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

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


class StockPicking(models.Model):
_inherit = ["stock.picking", "base.exception"]
_name = "stock.picking"

@api.model
def test_all_draft_pickings(self):
picking_set = self.search([("state", "=", "draft")])
picking_set.detect_exceptions()
return True
check_on_validate = fields.Boolean(compute="_compute_check_on_validate")
check_on_confirm = fields.Boolean(compute="_compute_check_on_confirm")

# @api.model
# def test_all_draft_pickings(self):
# picking_set = self.search([("state", "=", "draft")])
# picking_set.detect_exceptions()
# return True

@api.model
def _reverse_field(self):
Expand All @@ -39,11 +43,50 @@ def onchange_ignore_exception(self):

def action_confirm(self):
for rec in self:
if rec.detect_exceptions() and not rec.ignore_exception:
if (
rec.detect_exceptions()
and not rec.ignore_exception
and rec.exception_ids.check_on_confirm
):
return rec._popup_exceptions()
return super().action_confirm()

def button_validate(self):
for rec in self:
if rec.detect_exceptions() and not rec.ignore_exception:
if rec.exception_ids.check_on_validate:
raise ValidationError(

Check warning on line 58 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L58

Added line #L58 was not covered by tests
"\n".join(rec.exception_ids.mapped("description"))
)
return super().button_validate()

@api.model
def _get_popup_action(self):
action = self.env.ref("stock_exception.action_stock_exception_confirm")
return action

def _check_exception(self):
if not self.env.context.get("check_exception", True):
return True

Check warning on line 70 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L70

Added line #L70 was not covered by tests
exception_ids = self.detect_exceptions()
if exception_ids and self.env.context.get("raise_exception", True):
exceptions = self.env["exception.rule"].browse(exception_ids)

Check warning on line 73 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L73

Added line #L73 was not covered by tests
for rec in exceptions:
if rec.check_on_confirm and self.state == "assigned":
raise ValidationError("\n".join(rec.mapped("description")))

Check warning on line 76 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L76

Added line #L76 was not covered by tests
if rec.check_on_validate and self.state == "done":
raise ValidationError("\n".join(rec.mapped("description")))

Check warning on line 78 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L78

Added line #L78 was not covered by tests

def _compute_check_on_validate(self):
for rec in self:
if rec.exception_ids.check_on_validate:
rec.check_on_validate = True

Check warning on line 83 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L83

Added line #L83 was not covered by tests
else:
rec.check_on_validate = False

def _compute_check_on_confirm(self):
for rec in self:
if rec.exception_ids.check_on_confirm:
rec.check_on_confirm = True

Check warning on line 90 in stock_exception/models/stock.py

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L90

Added line #L90 was not covered by tests
else:
rec.check_on_confirm = False
20 changes: 20 additions & 0 deletions stock_exception/views/exception_rule_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<odoo>
<record id="view_exception_rule_form" model="ir.ui.view">
<field name="name">exception.rule.form</field>
<field name="model">exception.rule</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_form" />
<field name="arch" type="xml">
<field name="model" position="after">
<field
name="check_on_confirm"
attrs="{'invisible': [('model', '!=', 'stock.picking')]}"
/>
<field
name="check_on_validate"
attrs="{'invisible': [('model', '!=', 'stock.picking')]}"
/>
</field>
</field>
</record>
</odoo>
4 changes: 3 additions & 1 deletion stock_exception/views/stock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class="alert alert-danger"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('exceptions_summary', '=', False)]}"
attrs="{'invisible': ['|', ('exceptions_summary', '=', False), ('check_on_validate', '=', False)]}"
>
<p>
<strong
Expand All @@ -50,6 +50,8 @@
groups='base_exception.group_exception_rule_manager'
/>
<field name="exception_ids" widget="many2many_tags" readonly="True" />
<field name="check_on_validate" invisible="1" />
<field name="check_on_confirm" invisible="1" />
</xpath>
</field>
</record>
Expand Down

0 comments on commit 8bd838d

Please sign in to comment.