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

View File

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

View File

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