mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_archive_constraint: black, isort, prettier
This commit is contained in:
committed by
Marçal Isern
parent
ef8357a62c
commit
55b491e3af
@@ -10,43 +10,52 @@ class ProductProduct(models.Model):
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_quant(self):
|
||||
res = self.env['stock.quant'].search(
|
||||
res = self.env["stock.quant"].search(
|
||||
[
|
||||
('location_id.usage', 'in', ('internal', 'transit')),
|
||||
('product_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('quantity', '!=', 0.0)
|
||||
], limit=1
|
||||
("location_id.usage", "in", ("internal", "transit")),
|
||||
("product_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("quantity", "!=", 0.0),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive product '%s' which has "
|
||||
"associated stock quantities." % res[0].product_id.display_name)
|
||||
_(
|
||||
"It is not possible to archive product '%s' which has "
|
||||
"associated stock quantities." % res[0].product_id.display_name
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_move(self):
|
||||
res = self.env['stock.move'].search(
|
||||
res = self.env["stock.move"].search(
|
||||
[
|
||||
('product_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('state', 'not in', ('done', 'cancel'))
|
||||
], limit=1
|
||||
("product_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("state", "not in", ("done", "cancel")),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive product '%s' which has "
|
||||
"associated picking lines." % res[0].product_id.display_name)
|
||||
_(
|
||||
"It is not possible to archive product '%s' which has "
|
||||
"associated picking lines." % res[0].product_id.display_name
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_move_line(self):
|
||||
res = self.env['stock.move.line'].search(
|
||||
res = self.env["stock.move.line"].search(
|
||||
[
|
||||
('product_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('state', 'not in', ('done', 'cancel'))
|
||||
], limit=1
|
||||
("product_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("state", "not in", ("done", "cancel")),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive product '%s' which has "
|
||||
"associated stock reservations." % res[0].product_id.display_name)
|
||||
_(
|
||||
"It is not possible to archive product '%s' which has "
|
||||
"associated stock reservations." % res[0].product_id.display_name
|
||||
)
|
||||
)
|
||||
|
||||
@@ -10,51 +10,60 @@ class StockLocation(models.Model):
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_quant(self):
|
||||
res = self.env['stock.quant'].search(
|
||||
res = self.env["stock.quant"].search(
|
||||
[
|
||||
'&',
|
||||
('location_id.usage', 'in', ('internal', 'transit')),
|
||||
'|',
|
||||
('location_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('location_id', 'child_of', self.filtered(lambda x: not x.active).ids),
|
||||
], limit=1
|
||||
"&",
|
||||
("location_id.usage", "in", ("internal", "transit")),
|
||||
"|",
|
||||
("location_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("location_id", "child_of", self.filtered(lambda x: not x.active).ids),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive location '%s' which has "
|
||||
"associated stock quantities." % res[0].display_name)
|
||||
_(
|
||||
"It is not possible to archive location '%s' which has "
|
||||
"associated stock quantities." % res[0].display_name
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_move(self):
|
||||
res = self.env['stock.move'].search(
|
||||
res = self.env["stock.move"].search(
|
||||
[
|
||||
'&',
|
||||
('state', 'not in', ('done', 'cancel')),
|
||||
'|',
|
||||
('location_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('location_id', 'child_of', self.filtered(lambda x: not x.active).ids)
|
||||
], limit=1
|
||||
"&",
|
||||
("state", "not in", ("done", "cancel")),
|
||||
"|",
|
||||
("location_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("location_id", "child_of", self.filtered(lambda x: not x.active).ids),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive location '%s' which has "
|
||||
"associated picking lines." % res[0].display_name)
|
||||
_(
|
||||
"It is not possible to archive location '%s' which has "
|
||||
"associated picking lines." % res[0].display_name
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("active")
|
||||
def _check_active_stock_archive_constraint_stock_move_line(self):
|
||||
res = self.env['stock.move.line'].search(
|
||||
res = self.env["stock.move.line"].search(
|
||||
[
|
||||
'&',
|
||||
('state', 'not in', ('done', 'cancel')),
|
||||
'|',
|
||||
('location_id', 'in', self.filtered(lambda x: not x.active).ids),
|
||||
('location_id', 'child_of', self.filtered(lambda x: not x.active).ids)
|
||||
], limit=1
|
||||
"&",
|
||||
("state", "not in", ("done", "cancel")),
|
||||
"|",
|
||||
("location_id", "in", self.filtered(lambda x: not x.active).ids),
|
||||
("location_id", "child_of", self.filtered(lambda x: not x.active).ids),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if res:
|
||||
raise ValidationError(
|
||||
_("It is not possible to archive location '%s' which has "
|
||||
"associated stock reservations." % res[0].display_name)
|
||||
_(
|
||||
"It is not possible to archive location '%s' which has "
|
||||
"associated stock reservations." % res[0].display_name
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
# Copyright 2020 Tecnativa - Víctor Martínez
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo.tests.common import SavepointCase, Form
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import Form, SavepointCase
|
||||
|
||||
|
||||
class TestLocationArchiveConstraint(SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.product_1 = cls._create_product(cls, 'Product 1')
|
||||
cls.product_2 = cls._create_product(cls, 'Product 2')
|
||||
stock_location_stock = cls.env.ref('stock.stock_location_stock')
|
||||
cls.product_1 = cls._create_product(cls, "Product 1")
|
||||
cls.product_2 = cls._create_product(cls, "Product 2")
|
||||
stock_location_stock = cls.env.ref("stock.stock_location_stock")
|
||||
cls.stock_location = cls._create_stock_location(
|
||||
cls, "%s (Copy)" % (stock_location_stock.name)
|
||||
)
|
||||
@@ -22,21 +21,21 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
cls.stock_location_child.location_id = cls.stock_location
|
||||
|
||||
def _create_product(self, name):
|
||||
product_form = Form(self.env['product.product'])
|
||||
product_form = Form(self.env["product.product"])
|
||||
product_form.name = name
|
||||
product_form.type = 'product'
|
||||
product_form.type = "product"
|
||||
return product_form.save()
|
||||
|
||||
def _create_stock_location(self, name):
|
||||
stock_location_form = Form(self.env['stock.location'])
|
||||
stock_location_form = Form(self.env["stock.location"])
|
||||
stock_location_form.name = name
|
||||
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()
|
||||
|
||||
def _create_stock_inventory(self, location_id, product_id, qty):
|
||||
stock_inventory_form = Form(self.env['stock.inventory'])
|
||||
stock_inventory_form.name = 'INV: %s' % product_id.display_name
|
||||
stock_inventory_form.filter = 'product'
|
||||
stock_inventory_form = Form(self.env["stock.inventory"])
|
||||
stock_inventory_form.name = "INV: %s" % product_id.display_name
|
||||
stock_inventory_form.filter = "product"
|
||||
stock_inventory_form.product_id = product_id
|
||||
stock_inventory_form.location_id = location_id
|
||||
stock_inventory = stock_inventory_form.save()
|
||||
@@ -46,7 +45,7 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
stock_inventory.action_validate()
|
||||
|
||||
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"])
|
||||
stock_move_form.name = product_id.display_name
|
||||
stock_move_form.location_id = location_id
|
||||
stock_move_form.location_dest_id = location_dest_id
|
||||
@@ -56,26 +55,25 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
stock_move._action_done()
|
||||
|
||||
def _create_stock_move_line(self, location_id, location_dest_id, product_id, qty):
|
||||
stock_move_line_form = Form(self.env['stock.move.line'])
|
||||
stock_move_line_form = Form(self.env["stock.move.line"])
|
||||
stock_move_line_form.location_id = location_id
|
||||
stock_move_line_form.location_dest_id = location_dest_id
|
||||
stock_move_line_form.product_id = product_id
|
||||
stock_move_line_form.product_uom_qty = qty
|
||||
stock_move_line_form.qty_done = qty
|
||||
stock_move_line_form.state = 'done'
|
||||
stock_move_line_form.state = "done"
|
||||
stock_move_line_form.save()
|
||||
|
||||
def _create_stock_picking(self, location_id, location_dest_id, product_id, qty):
|
||||
stock_picking_form = Form(self.env['stock.picking'])
|
||||
stock_picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
|
||||
stock_picking_form = Form(self.env["stock.picking"])
|
||||
stock_picking_form.picking_type_id = self.env.ref("stock.picking_type_in")
|
||||
with stock_picking_form.move_ids_without_package.new() as line:
|
||||
line.product_id = product_id
|
||||
line.product_uom_qty = qty
|
||||
stock_picking = stock_picking_form.save()
|
||||
stock_picking.write({
|
||||
'location_id': location_id.id,
|
||||
'location_dest_id': location_dest_id.id,
|
||||
})
|
||||
stock_picking.write(
|
||||
{"location_id": location_id.id, "location_dest_id": location_dest_id.id}
|
||||
)
|
||||
stock_picking.action_confirm()
|
||||
for line in stock_picking.move_ids_without_package:
|
||||
line.quantity_done = line.product_uom_qty
|
||||
@@ -95,8 +93,10 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
|
||||
def test_archive_product_with_stock_move_in(self):
|
||||
self._create_stock_move(
|
||||
self.env.ref('stock.stock_location_suppliers'),
|
||||
self.stock_location, self.product_2, 20.00
|
||||
self.env.ref("stock.stock_location_suppliers"),
|
||||
self.stock_location,
|
||||
self.product_2,
|
||||
20.00,
|
||||
)
|
||||
self.product_1.active = False
|
||||
self.assertFalse(self.product_1.active)
|
||||
@@ -105,8 +105,10 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
|
||||
def test_archive_product_with_stock_move_line_in(self):
|
||||
self._create_stock_move_line(
|
||||
self.env.ref('stock.stock_location_suppliers'),
|
||||
self.stock_location, self.product_2, 20.00
|
||||
self.env.ref("stock.stock_location_suppliers"),
|
||||
self.stock_location,
|
||||
self.product_2,
|
||||
20.00,
|
||||
)
|
||||
self.product_1.active = False
|
||||
self.assertFalse(self.product_1.active)
|
||||
@@ -115,8 +117,10 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
|
||||
def test_archive_product_with_stock_picking_in(self):
|
||||
self._create_stock_picking(
|
||||
self.env.ref('stock.stock_location_suppliers'),
|
||||
self.stock_location, self.product_2, 20.00
|
||||
self.env.ref("stock.stock_location_suppliers"),
|
||||
self.stock_location,
|
||||
self.product_2,
|
||||
20.00,
|
||||
)
|
||||
self.product_1.active = False
|
||||
self.assertFalse(self.product_1.active)
|
||||
@@ -125,12 +129,16 @@ class TestLocationArchiveConstraint(SavepointCase):
|
||||
|
||||
def test_archive_product_with_stock_picking_in_out(self):
|
||||
self._create_stock_picking(
|
||||
self.env.ref('stock.stock_location_suppliers'),
|
||||
self.stock_location, self.product_2, 20.00
|
||||
self.env.ref("stock.stock_location_suppliers"),
|
||||
self.stock_location,
|
||||
self.product_2,
|
||||
20.00,
|
||||
)
|
||||
self._create_stock_picking(
|
||||
self.stock_location,
|
||||
self.env.ref('stock.stock_location_customers'), self.product_2, 20.00
|
||||
self.env.ref("stock.stock_location_customers"),
|
||||
self.product_2,
|
||||
20.00,
|
||||
)
|
||||
self.product_1.active = False
|
||||
self.assertFalse(self.product_1.active)
|
||||
|
||||
Reference in New Issue
Block a user