Skip to content

Commit

Permalink
[MIG] stock_exception: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisha-serpentcs authored and Nikul-OSI committed Jul 3, 2024
1 parent 0083c42 commit 8fe9539
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
5 changes: 5 additions & 0 deletions stock_exception/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Contributors

- Tharathip Chaweewongphan <[email protected]>

- Open Source Integrators http://www.opensourceintegrators.com

- Urvisha Desai [email protected]
- Nikul Chaudhary [email protected]

Maintainers
-----------

Expand Down
6 changes: 6 additions & 0 deletions stock_exception/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def action_confirm(self):
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:
return rec._popup_exceptions()
return super().button_validate()

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

View check run for this annotation

Codecov / codecov/patch

stock_exception/models/stock.py#L50

Added line #L50 was not covered by tests

@api.model
def _get_popup_action(self):
action = self.env.ref("stock_exception.action_stock_exception_confirm")
Expand Down
5 changes: 5 additions & 0 deletions stock_exception/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
- Tharathip Chaweewongphan \<<[email protected]>\>

* Open Source Integrators <http://www.opensourceintegrators.com>

* Urvisha Desai <[email protected]>
* Nikul Chaudhary <[email protected]>
5 changes: 5 additions & 0 deletions stock_exception/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Tharathip Chaweewongphan &lt;<a class="reference external" href="mailto:tharathipc&#64;ecosoft.co.th">tharathipc&#64;ecosoft.co.th</a>&gt;</li>
<li>Open Source Integrators <a class="reference external" href="http://www.opensourceintegrators.com">http://www.opensourceintegrators.com</a><ul>
<li>Urvisha Desai <a class="reference external" href="mailto:udesai&#64;opensourceintegrators.com">udesai&#64;opensourceintegrators.com</a></li>
<li>Nikul Chaudhary <a class="reference external" href="mailto:nchaudhary&#64;opensourceintegrators.com">nchaudhary&#64;opensourceintegrators.com</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
1 change: 1 addition & 0 deletions stock_exception/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_stock_exception
113 changes: 113 additions & 0 deletions stock_exception/tests/test_stock_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo.tests import Form
from odoo.tests.common import TransactionCase


class TestStockException(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.res_users_model = cls.env["res.users"]
cls.product_model = cls.env["product.product"]
cls.exception_rule = cls.env["exception.rule"]

cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.picking_type_id = cls.env.ref("stock.picking_type_out")
cls.stock_location = cls.env.ref("stock.stock_location_stock")
cls.customer_location = cls.env.ref("stock.stock_location_customers")

# Create a product:
cls.product_1 = cls.product_model.create(
{
"name": "Test Product 1",
"type": "product",
"default_code": "PROD1",
"uom_id": cls.uom_unit.id,
}
)

# Create a Picking:
cls.picking = cls.env["stock.picking"].create(
{
"location_id": cls.stock_location.id,
"location_dest_id": cls.customer_location.id,
"picking_type_id": cls.picking_type_id.id,
"move_ids": [
(
0,
0,
{
"name": cls.product_1.name,
"product_id": cls.product_1.id,
"product_uom_qty": 1,
"product_uom": cls.product_1.uom_id.id,
"location_id": cls.stock_location.id,
"location_dest_id": cls.customer_location.id,
},
)
],
}
)

def test01_confirm_picking_fail_by_py(self):
self.stock_exception = self.exception_rule.create(
{
"name": "No Partner",
"sequence": 10,
"model": "stock.picking",
"exception_type": "by_py_code",
"code": "if not self.partner_id: failed=True",
}
)
exception_action = self.picking.action_confirm()
self.assertEqual(exception_action.get("res_model"), "stock.exception.confirm")
self.assertTrue(self.picking.exceptions_summary)
self.assertTrue(self.picking.exception_ids)
rules = self.env["exception.rule"].browse(self.picking.exception_ids.ids)
self.assertIn(self.picking.id, rules.mapped("picking_ids.id"))

self.picking.button_validate()
self.assertTrue(self.picking.exceptions_summary)

# Test ignore exception make possible for the picking to validate
self.assertEqual(self.picking.state, "draft")
self.picking.action_ignore_exceptions()
self.assertTrue(self.picking.ignore_exception)
self.assertFalse(self.picking.exceptions_summary)
self.picking.action_confirm()
self.assertEqual(self.picking.state, "confirmed")

def test02_confirm_picking_fail_by_domain(self):
self.exception_method = self.env["exception.rule"].create(
{
"name": "No Partner",
"sequence": 11,
"model": "stock.picking",
"domain": "[('partner_id', '=', False)]",
"exception_type": "by_domain",
}
)
exception_action = self.picking.action_confirm()
self.assertEqual(exception_action.get("res_model"), "stock.exception.confirm")
self.assertTrue(self.picking.exceptions_summary)
self.assertTrue(self.picking.exception_ids)
exception_form = Form(
self.env["stock.exception.confirm"].with_context(
**exception_action.get("context")
),
)
stock_exception = exception_form.save()
stock_exception.ignore = True
stock_exception.action_confirm()

def test03_call_picking_method(self):
self.env["stock.picking"].test_all_draft_pickings()
self.env["stock.picking"]._reverse_field()
self.picking.move_ids._get_main_records()
self.picking.move_ids._reverse_field()

def test_confirm_picking(self):
self.assertEqual(self.picking.state, "draft")
self.picking.action_confirm()
self.assertEqual(self.picking.state, "confirmed")
4 changes: 2 additions & 2 deletions 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)]}"
invisible="not exceptions_summary"
>
<p>
<strong
Expand All @@ -46,7 +46,7 @@
<xpath expr="//field[@name='date_deadline']/.." position="inside">
<field
name="ignore_exception"
states="waiting,confirmed,assigned"
invisible="state not in ('waiting','confirmed','assigned')"
groups='base_exception.group_exception_rule_manager'
/>
<field name="exception_ids" widget="many2many_tags" readonly="True" />
Expand Down

0 comments on commit 8fe9539

Please sign in to comment.