mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_archive_constraint: Migration to 13.0
This commit is contained in:
committed by
Marçal Isern
parent
55b491e3af
commit
e2e5d7ed1d
@@ -36,8 +36,8 @@ Allows to block archiving locations with associated stock.quant or stock.move.
|
|||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
#. Go to Settings,> Users> Edit a user and check the "Manage Multiple Stock Locations" permission
|
#. Go to Settings > Users > Edit a user and check the "Manage Multiple Stock Locations" permission
|
||||||
#. Go to Inventory> Settings> Locations and disable one
|
#. Go to Inventory > Settings > Locations and disable one
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Stock archive constraint",
|
"name": "Stock archive constraint",
|
||||||
"version": "12.0.1.0.0",
|
"version": "13.0.1.0.0",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"website": "https://github.com/stock-logistics-warehouse",
|
"website": "https://github.com/stock-logistics-warehouse",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
#. Go to Settings,> Users> Edit a user and check the "Manage Multiple Stock Locations" permission
|
#. Go to Settings > Users > Edit a user and check the "Manage Multiple Stock Locations" permission
|
||||||
#. Go to Inventory> Settings> Locations and disable one
|
#. Go to Inventory > Settings > Locations and disable one
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2020 Tecnativa - Víctor Martínez
|
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||||
|
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
@@ -9,6 +9,7 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
cls.company = cls.env.ref("base.main_company")
|
||||||
cls.product_1 = cls._create_product(cls, "Product 1")
|
cls.product_1 = cls._create_product(cls, "Product 1")
|
||||||
cls.product_2 = cls._create_product(cls, "Product 2")
|
cls.product_2 = cls._create_product(cls, "Product 2")
|
||||||
stock_location_stock = cls.env.ref("stock.stock_location_stock")
|
stock_location_stock = cls.env.ref("stock.stock_location_stock")
|
||||||
@@ -32,17 +33,15 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
stock_location_form.usage = self.env.ref("stock.stock_location_stock").usage
|
stock_location_form.usage = self.env.ref("stock.stock_location_stock").usage
|
||||||
return stock_location_form.save()
|
return stock_location_form.save()
|
||||||
|
|
||||||
def _create_stock_inventory(self, location_id, product_id, qty):
|
def _create_stock_quant(self, location_id, product_id, qty):
|
||||||
stock_inventory_form = Form(self.env["stock.inventory"])
|
self.env["stock.quant"].create(
|
||||||
stock_inventory_form.name = "INV: %s" % product_id.display_name
|
{
|
||||||
stock_inventory_form.filter = "product"
|
"company_id": self.company.id,
|
||||||
stock_inventory_form.product_id = product_id
|
"location_id": location_id.id,
|
||||||
stock_inventory_form.location_id = location_id
|
"product_id": product_id.id,
|
||||||
stock_inventory = stock_inventory_form.save()
|
"quantity": qty,
|
||||||
stock_inventory.action_start()
|
}
|
||||||
for line_id in stock_inventory.line_ids:
|
)
|
||||||
line_id.product_qty = qty
|
|
||||||
stock_inventory.action_validate()
|
|
||||||
|
|
||||||
def _create_stock_move(self, location_id, location_dest_id, product_id, qty):
|
def _create_stock_move(self, location_id, location_dest_id, product_id, qty):
|
||||||
stock_move_form = Form(self.env["stock.move"])
|
stock_move_form = Form(self.env["stock.move"])
|
||||||
@@ -55,14 +54,18 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
stock_move._action_done()
|
stock_move._action_done()
|
||||||
|
|
||||||
def _create_stock_move_line(self, location_id, location_dest_id, product_id, qty):
|
def _create_stock_move_line(self, location_id, location_dest_id, product_id, qty):
|
||||||
stock_move_line_form = Form(self.env["stock.move.line"])
|
self.env["stock.move.line"].create(
|
||||||
stock_move_line_form.location_id = location_id
|
{
|
||||||
stock_move_line_form.location_dest_id = location_dest_id
|
"company_id": self.company.id,
|
||||||
stock_move_line_form.product_id = product_id
|
"location_id": location_id.id,
|
||||||
stock_move_line_form.product_uom_qty = qty
|
"location_dest_id": location_dest_id.id,
|
||||||
stock_move_line_form.qty_done = qty
|
"product_id": product_id.id,
|
||||||
stock_move_line_form.state = "done"
|
"product_uom_qty": qty,
|
||||||
stock_move_line_form.save()
|
"product_uom_id": product_id.uom_id.id,
|
||||||
|
"qty_done": qty,
|
||||||
|
"state": "done",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def _create_stock_picking(self, location_id, location_dest_id, product_id, qty):
|
def _create_stock_picking(self, location_id, location_dest_id, product_id, qty):
|
||||||
stock_picking_form = Form(self.env["stock.picking"])
|
stock_picking_form = Form(self.env["stock.picking"])
|
||||||
@@ -146,14 +149,14 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
self.assertFalse(self.product_2.active)
|
self.assertFalse(self.product_2.active)
|
||||||
|
|
||||||
def test_archive_product_stock_location(self):
|
def test_archive_product_stock_location(self):
|
||||||
self._create_stock_inventory(self.stock_location, self.product_2, 20.00)
|
self._create_stock_quant(self.stock_location, self.product_2, 20.00)
|
||||||
self.product_1.active = False
|
self.product_1.active = False
|
||||||
self.assertFalse(self.product_1.active)
|
self.assertFalse(self.product_1.active)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.product_2.active = False
|
self.product_2.active = False
|
||||||
|
|
||||||
def test_archive_product_stock_location_child(self):
|
def test_archive_product_stock_location_child(self):
|
||||||
self._create_stock_inventory(self.stock_location_child, self.product_2, 20.00)
|
self._create_stock_quant(self.stock_location_child, self.product_2, 20.00)
|
||||||
self.product_1.active = False
|
self.product_1.active = False
|
||||||
self.assertFalse(self.product_1.active)
|
self.assertFalse(self.product_1.active)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
@@ -170,9 +173,9 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
self.assertFalse(self.stock_location.active)
|
self.assertFalse(self.stock_location.active)
|
||||||
|
|
||||||
def test_archive_stock_location(self):
|
def test_archive_stock_location(self):
|
||||||
self._create_stock_inventory(self.stock_location, self.product_2, 20.00)
|
self._create_stock_quant(self.stock_location, self.product_2, 20.00)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.stock_location.active = False
|
self.stock_location.with_context(do_not_check_quant=True).active = False
|
||||||
|
|
||||||
def test_archive_unarchive_stock_location_child(self):
|
def test_archive_unarchive_stock_location_child(self):
|
||||||
self.stock_location_child.active = False
|
self.stock_location_child.active = False
|
||||||
@@ -181,6 +184,6 @@ class TestLocationArchiveConstraint(SavepointCase):
|
|||||||
self.assertTrue(self.stock_location_child.active)
|
self.assertTrue(self.stock_location_child.active)
|
||||||
|
|
||||||
def test_archive_stock_location_child(self):
|
def test_archive_stock_location_child(self):
|
||||||
self._create_stock_inventory(self.stock_location_child, self.product_2, 20.00)
|
self._create_stock_quant(self.stock_location_child, self.product_2, 20.00)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.stock_location.active = False
|
self.stock_location.with_context(do_not_check_quant=True).active = False
|
||||||
|
|||||||
Reference in New Issue
Block a user