Skip to content

Commit

Permalink
[MIG] purchase_stock_operating_unit: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidderen-nsi committed May 29, 2024
1 parent e1711e2 commit cffcade
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion purchase_stock_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Purchase Stock Operating Unit",
"summary": "Copies the operating unit of purchase picking to the stock picking",
"version": "15.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Purchase Management",
Expand Down
2 changes: 1 addition & 1 deletion purchase_stock_operating_unit/models/__init__.py
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
35 changes: 34 additions & 1 deletion purchase_stock_operating_unit/models/purchase.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
# Copyright 2023 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

picking_type_id = fields.Many2one(
compute="_compute_picking_type_id", store=True, readonly=False
)
operating_unit_id = fields.Many2one(
compute="_compute_operating_unit_id",
store=True,
readonly=False,
)

@api.depends("operating_unit_id")
def _compute_picking_type_id(self):
for purchase in self:
if purchase.operating_unit_id:
purchase.picking_type_id = self.env["stock.picking.type"].search(
[
(
"warehouse_id.operating_unit_id",
"=",
purchase.operating_unit_id.id,
),
("code", "=", "incoming"),
],
limit=1,
)

@api.depends("picking_type_id")
def _compute_operating_unit_id(self):
for purchase in self:
if purchase.picking_type_id:
purchase.operating_unit_id = (
purchase.picking_type_id.warehouse_id.operating_unit_id
)

@api.constrains("operating_unit_id", "picking_type_id")
def _check_operating_unit_picking_type(self):
for rec in self:
Expand Down
15 changes: 0 additions & 15 deletions purchase_stock_operating_unit/models/purchase_order_line.py

This file was deleted.

14 changes: 14 additions & 0 deletions purchase_stock_operating_unit/models/stock_rule.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@


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.b2b = cls.env.ref("operating_unit.b2b_operating_unit")
user = cls.env["res.users"].browse(cls.user1_id)
user.operating_unit_ids = [(4, cls.b2b.id)]

def test_01_purchase_stock_operating_unit(self):
self.assertEqual(self.purchase1.state, "purchase")
Expand Down

0 comments on commit cffcade

Please sign in to comment.