-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] purchase_stock_operating_unit: Migration to 17.0
- Loading branch information
1 parent
e1711e2
commit bc7201f
Showing
6 changed files
with
77 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import purchase_order_line | ||
from . import purchase | ||
from . import stock_rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
purchase_stock_operating_unit/models/purchase_order_line.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockRule(models.Model): | ||
_inherit = "stock.rule" | ||
|
||
def _prepare_purchase_order(self, company_id, origins, values): | ||
res = super()._prepare_purchase_order(company_id, origins, values) | ||
if self.operating_unit_id: | ||
res["operating_unit_id"] = self.operating_unit_id.id | ||
return res |
36 changes: 21 additions & 15 deletions
36
purchase_stock_operating_unit/tests/test_purchase_stock_operating_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.exceptions import UserError | ||
from odoo.tests import Form | ||
from odoo.models import Command | ||
|
||
from odoo.addons.purchase_operating_unit.tests.test_purchase_operating_unit import ( | ||
TestPurchaseOperatingUnit, | ||
) | ||
|
||
|
||
class TestPurchaseStockOperatingUnit(TestPurchaseOperatingUnit): | ||
def setUp(self): | ||
super().setUp() | ||
self.warehouse_b2b = self.env.ref("stock_operating_unit.stock_warehouse_b2b") | ||
self.picking_type2 = self.env["stock.picking.type"].search( | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.warehouse_b2b = cls.env.ref("stock_operating_unit.stock_warehouse_b2b") | ||
cls.picking_type2 = cls.env["stock.picking.type"].search( | ||
[ | ||
("code", "=", "incoming"), | ||
("warehouse_id", "=", self.warehouse_b2b.id), | ||
("warehouse_id", "=", cls.warehouse_b2b.id), | ||
], | ||
limit=1, | ||
) | ||
# Add permission b2b operating unit in user1 | ||
self.b2b = self.env.ref("operating_unit.b2b_operating_unit") | ||
user = self.env["res.users"].browse(self.user1_id) | ||
user.operating_unit_ids = [(4, self.b2b.id)] | ||
cls.user1.write( | ||
{ | ||
"operating_unit_ids": [ | ||
Command.link(cls.b2b.id), | ||
], | ||
} | ||
) | ||
|
||
def test_01_purchase_stock_operating_unit(self): | ||
self.assertEqual(self.purchase1.state, "purchase") | ||
self.assertEqual( | ||
self.purchase1.picking_ids.operating_unit_id, | ||
self.purchase1.picking_type_id.warehouse_id.operating_unit_id, | ||
) | ||
# Ensure that in case of picking type changes, | ||
# the operating unit is also updated. | ||
self.purchase1.button_cancel() | ||
self.purchase1.button_draft() | ||
# Check change picking type is not equal operating unit, it should error | ||
with self.assertRaises(UserError): | ||
with Form(self.purchase1) as po: | ||
po.picking_type_id = self.picking_type2 | ||
self.purchase1.picking_type_id = self.picking_type2 | ||
self.assertEqual( | ||
self.purchase1.operating_unit_id, | ||
self.purchase1.picking_type_id.warehouse_id.operating_unit_id, | ||
) |