[IMP] stock_inventory_exclude_sublocation: black, isort

This commit is contained in:
hveficent
2019-12-30 10:14:24 +01:00
committed by joan
parent 86657aea8c
commit 137a0d51a1
3 changed files with 192 additions and 151 deletions

View File

@@ -8,18 +8,12 @@
"its child locations.",
"version": "12.0.1.0.1",
"development_status": "Mature",
"author": "Eficent, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"author": "Eficent, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": [
"stock",
],
"data": [
'views/stock_inventory_view.xml',
],
"depends": ["stock"],
"data": ["views/stock_inventory_view.xml"],
"license": "AGPL-3",
'installable': True,
'application': False,
"installable": True,
"application": False,
}

View File

@@ -7,12 +7,15 @@ from odoo import fields, models
class Inventory(models.Model):
_inherit = 'stock.inventory'
_inherit = "stock.inventory"
exclude_sublocation = fields.Boolean(
string='Exclude Sublocations', default=False,
track_visibility='onchange', readonly=True,
states={'draft': [('readonly', False)]})
string="Exclude Sublocations",
default=False,
track_visibility="onchange",
readonly=True,
states={"draft": [("readonly", False)]},
)
def _get_inventory_lines_values(self):
"""Discard inventory lines that are from sublocations if option
@@ -25,6 +28,6 @@ class Inventory(models.Model):
return vals
new_vals = []
for val in vals:
if val['location_id'] == self.location_id.id:
if val["location_id"] == self.location_id.id:
new_vals.append(val)
return new_vals

View File

@@ -6,184 +6,228 @@ from odoo.tests.common import TransactionCase
class TestStockInventoryExcludeSublocation(TransactionCase):
def setUp(self):
super(TestStockInventoryExcludeSublocation, self).setUp()
self.inventory_model = self.env['stock.inventory']
self.location_model = self.env['stock.location']
self.lot_model = self.env['stock.production.lot']
self.quant_model = self.env['stock.quant']
self.package_model = self.env['stock.quant.package']
self.res_users_model = self.env['res.users']
self.inventory_model = self.env["stock.inventory"]
self.location_model = self.env["stock.location"]
self.lot_model = self.env["stock.production.lot"]
self.quant_model = self.env["stock.quant"]
self.package_model = self.env["stock.quant.package"]
self.res_users_model = self.env["res.users"]
self.company = self.env.ref('base.main_company')
self.partner = self.ref('base.res_partner_4')
self.grp_stock_manager = self.env.ref('stock.group_stock_manager')
self.grp_tracking_owner = self.env.ref('stock.group_tracking_owner')
self.grp_production_lot = self.env.ref('stock.group_production_lot')
self.grp_tracking_lot = self.env.ref('stock.group_tracking_lot')
self.company = self.env.ref("base.main_company")
self.partner = self.ref("base.res_partner_4")
self.grp_stock_manager = self.env.ref("stock.group_stock_manager")
self.grp_tracking_owner = self.env.ref("stock.group_tracking_owner")
self.grp_production_lot = self.env.ref("stock.group_production_lot")
self.grp_tracking_lot = self.env.ref("stock.group_tracking_lot")
self.user = self.res_users_model.create({
'name': 'Test Account User',
'login': 'user_1',
'email': 'example@yourcompany.com',
'company_id': self.company.id,
'company_ids': [(4, self.company.id)],
'groups_id': [(6, 0, [
self.user = self.res_users_model.create(
{
"name": "Test Account User",
"login": "user_1",
"email": "example@yourcompany.com",
"company_id": self.company.id,
"company_ids": [(4, self.company.id)],
"groups_id": [
(
6,
0,
[
self.grp_stock_manager.id,
self.grp_tracking_owner.id,
self.grp_production_lot.id,
self.grp_tracking_lot.id
])]
})
self.grp_tracking_lot.id,
],
)
],
}
)
self.product1 = self.env['product.product'].create({
'name': 'Product for parent location',
'type': 'product',
'default_code': 'PROD1',
})
self.product2 = self.env['product.product'].create({
'name': 'Product for child location',
'type': 'product',
'default_code': 'PROD2',
})
self.location = self.location_model.create({
'name': 'Inventory tests',
'usage': 'internal',
})
self.sublocation = self.location_model.create({
'name': 'Inventory sublocation test',
'usage': 'internal',
'location_id': self.location.id
})
self.lot_a = self.lot_model.create({
'name': 'Lot for product1',
'product_id': self.product1.id
})
self.lot_b = self.lot_model.create({
'name': 'Lot for product1',
'product_id': self.product2.id
})
self.package = self.package_model.create({'name': 'PACK00TEST1'})
self.product1 = self.env["product.product"].create(
{
"name": "Product for parent location",
"type": "product",
"default_code": "PROD1",
}
)
self.product2 = self.env["product.product"].create(
{
"name": "Product for child location",
"type": "product",
"default_code": "PROD2",
}
)
self.location = self.location_model.create(
{"name": "Inventory tests", "usage": "internal"}
)
self.sublocation = self.location_model.create(
{
"name": "Inventory sublocation test",
"usage": "internal",
"location_id": self.location.id,
}
)
self.lot_a = self.lot_model.create(
{"name": "Lot for product1", "product_id": self.product1.id}
)
self.lot_b = self.lot_model.create(
{"name": "Lot for product1", "product_id": self.product2.id}
)
self.package = self.package_model.create({"name": "PACK00TEST1"})
# Add a product in each location
starting_inv = self.inventory_model.create({
'name': 'Starting inventory',
'filter': 'product',
'line_ids': [
(0, 0, {
'product_id': self.product1.id,
'product_uom_id': self.env.ref(
"uom.product_uom_unit").id,
'product_qty': 2.0,
'location_id': self.location.id,
'prod_lot_id': self.lot_a.id
}),
(0, 0, {
'product_id': self.product2.id,
'product_uom_id': self.env.ref(
"uom.product_uom_unit").id,
'product_qty': 4.0,
'location_id': self.sublocation.id,
'prod_lot_id': self.lot_b.id
}),
starting_inv = self.inventory_model.create(
{
"name": "Starting inventory",
"filter": "product",
"line_ids": [
(
0,
0,
{
"product_id": self.product1.id,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
"product_qty": 2.0,
"location_id": self.location.id,
"prod_lot_id": self.lot_a.id,
},
),
(
0,
0,
{
"product_id": self.product2.id,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
"product_qty": 4.0,
"location_id": self.sublocation.id,
"prod_lot_id": self.lot_b.id,
},
),
],
})
}
)
starting_inv.action_validate()
def _create_inventory_all_products(self, name, location,
exclude_sublocation):
inventory = self.inventory_model.create({
'name': name,
'filter': 'none',
'location_id': location.id,
'exclude_sublocation': exclude_sublocation
})
def _create_inventory_all_products(self, name, location, exclude_sublocation):
inventory = self.inventory_model.create(
{
"name": name,
"filter": "none",
"location_id": location.id,
"exclude_sublocation": exclude_sublocation,
}
)
return inventory
def test_not_excluding_sublocations(self):
"""Check if products in sublocations are included into the inventory
if the excluding sublocations option is disabled."""
inventory_location = self._create_inventory_all_products(
'location inventory', self.location, False)
"location inventory", self.location, False
)
inventory_location.action_start()
inventory_location.action_validate()
lines = inventory_location.line_ids
self.assertEqual(len(lines), 2, 'Not all expected products are '
'included')
self.assertEqual(len(lines), 2, "Not all expected products are " "included")
def test_excluding_sublocations(self):
"""Check if products in sublocations are not included if the exclude
sublocations is enabled."""
inventory_location = self._create_inventory_all_products(
'location inventory', self.location, True)
"location inventory", self.location, True
)
inventory_sublocation = self._create_inventory_all_products(
'sublocation inventory', self.sublocation, True)
"sublocation inventory", self.sublocation, True
)
inventory_location.action_start()
inventory_location.action_validate()
inventory_sublocation.action_start()
inventory_sublocation.action_validate()
lines_location = inventory_location.line_ids
lines_sublocation = inventory_sublocation.line_ids
self.assertEqual(len(lines_location), 1,
'The products in the sublocations are not excluded')
self.assertEqual(len(lines_sublocation), 1,
'The products in the sublocations are not excluded')
self.assertEqual(
len(lines_location), 1, "The products in the sublocations are not excluded"
)
self.assertEqual(
len(lines_sublocation),
1,
"The products in the sublocations are not excluded",
)
def test_lot_excluding_sublocation(self):
"""Check if the sublocations are excluded when using lots."""
inventory = self.inventory_model.sudo(self.user.id).create({
'name': 'Inventory lot',
'filter': 'lot',
'location_id': self.location.id,
'lot_id': self.lot_a.id,
'exclude_sublocation': True
})
inventory = self.inventory_model.sudo(self.user.id).create(
{
"name": "Inventory lot",
"filter": "lot",
"location_id": self.location.id,
"lot_id": self.lot_a.id,
"exclude_sublocation": True,
}
)
inventory.action_start()
inventory.action_validate()
lines = inventory.line_ids
self.assertEqual(len(lines), 1, 'The products in the sublocations are '
'not excluded with lots.')
self.assertEqual(
len(lines),
1,
"The products in the sublocations are " "not excluded with lots.",
)
def test_product_and_owner_excluding_sublocation(self):
"""Check if sublocations are excluded when filtering by owner and
product."""
self.quant_model.create({
'product_id': self.product1.id,
'location_id': self.location.id,
'quantity': 1,
'owner_id': self.partner,
})
inventory = self.inventory_model.sudo(self.user.id).create({
'name': 'Inventory lot',
'filter': 'product_owner',
'location_id': self.location.id,
'product_id': self.product1.id,
'partner_id': self.partner,
'exclude_sublocation': True
})
self.quant_model.create(
{
"product_id": self.product1.id,
"location_id": self.location.id,
"quantity": 1,
"owner_id": self.partner,
}
)
inventory = self.inventory_model.sudo(self.user.id).create(
{
"name": "Inventory lot",
"filter": "product_owner",
"location_id": self.location.id,
"product_id": self.product1.id,
"partner_id": self.partner,
"exclude_sublocation": True,
}
)
inventory.action_start()
lines = inventory.line_ids
self.assertEqual(len(lines), 1,
'The products in the sublocations are '
'not excluded with product and owner filter.')
self.assertEqual(
len(lines),
1,
"The products in the sublocations are "
"not excluded with product and owner filter.",
)
def test_pack_excluding_sublocation(self):
"""Check if sublocations are excluded when filtering by package."""
self.quant_model.create({
'product_id': self.product1.id,
'location_id': self.location.id,
'quantity': 1,
'package_id': self.package.id
})
inventory = self.inventory_model.sudo(self.user.id).create({
'name': 'Inventory lot',
'filter': 'pack',
'location_id': self.location.id,
'package_id': self.package.id,
'exclude_sublocation': True
})
self.quant_model.create(
{
"product_id": self.product1.id,
"location_id": self.location.id,
"quantity": 1,
"package_id": self.package.id,
}
)
inventory = self.inventory_model.sudo(self.user.id).create(
{
"name": "Inventory lot",
"filter": "pack",
"location_id": self.location.id,
"package_id": self.package.id,
"exclude_sublocation": True,
}
)
inventory.action_start()
lines = inventory.line_ids
self.assertEqual(len(lines), 1, 'The products in the sublocations are '
'not excluded with package filter.')
self.assertEqual(
len(lines),
1,
"The products in the sublocations are " "not excluded with package filter.",
)