From fd8977714ce1fe48ea4b10bd133b714d3759d901 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 27 Feb 2020 11:13:25 +0100 Subject: [PATCH] [IMP] stock_generate_putaway_from_inventory: black --- .../__manifest__.py | 6 +-- .../models/stock_inventory.py | 49 +++++++++++-------- .../tests/test_generate_putaway.py | 37 ++++++++------ 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/stock_generate_putaway_from_inventory/__manifest__.py b/stock_generate_putaway_from_inventory/__manifest__.py index 9c48057fe..55045cfdb 100644 --- a/stock_generate_putaway_from_inventory/__manifest__.py +++ b/stock_generate_putaway_from_inventory/__manifest__.py @@ -10,8 +10,6 @@ "category": "Warehouse", "depends": ["stock_putaway_product"], "license": "AGPL-3", - "data": [ - "views/stock_inventory.xml", - ], - 'installable': True, + "data": ["views/stock_inventory.xml",], + "installable": True, } diff --git a/stock_generate_putaway_from_inventory/models/stock_inventory.py b/stock_generate_putaway_from_inventory/models/stock_inventory.py index ea2ad8e56..c4682c22a 100644 --- a/stock_generate_putaway_from_inventory/models/stock_inventory.py +++ b/stock_generate_putaway_from_inventory/models/stock_inventory.py @@ -7,7 +7,7 @@ from odoo.exceptions import UserError class StockLocation(models.Model): - _inherit = 'stock.location' + _inherit = "stock.location" def _get_putaway_strategy(self): if self.putaway_strategy_id: @@ -17,24 +17,28 @@ class StockLocation(models.Model): class StockInventory(models.Model): - _inherit = 'stock.inventory' + _inherit = "stock.inventory" @api.multi def generate_putaway_strategy(self): putaway_locations = {} for inventory in self: - if self.state != 'done': - raise UserError(_( - 'Please, validate the stock adjustment before')) + if self.state != "done": + raise UserError( + _("Please, validate the stock adjustment before") + ) strategy = self.location_id._get_putaway_strategy() if not strategy: - raise UserError(_( - 'Please, specify a Putaway Strategy ' - 'on the inventory\'s location (or a parent one)')) + raise UserError( + _( + "Please, specify a Putaway Strategy " + "on the inventory's location (or a parent one)" + ) + ) putaway_locations.update(self._prepare_putaway_locations(strategy)) for putaway_location in putaway_locations.values(): - putaway_location.pop('qty') - self.env['stock.product.putaway.strategy'].create(putaway_location) + putaway_location.pop("qty") + self.env["stock.product.putaway.strategy"].create(putaway_location) def _prepare_putaway_locations(self, strategy): self.ensure_one() @@ -42,26 +46,29 @@ class StockInventory(models.Model): for line in self.line_ids: if line.product_id.product_putaway_ids: continue - if (line.product_id.id not in putaway_locations - or line.product_qty > - putaway_locations[line.product_id.id]['qty']): + if ( + line.product_id.id not in putaway_locations + or line.product_qty + > putaway_locations[line.product_id.id]["qty"] + ): # If there is several lines for a product, we will use the # one having more products - putaway_locations[line.product_id.id] = line.\ - _prepare_putaway_location(strategy) + putaway_locations[ + line.product_id.id + ] = line._prepare_putaway_location(strategy) return putaway_locations class StockInventoryLine(models.Model): - _inherit = 'stock.inventory.line' + _inherit = "stock.inventory.line" def _prepare_putaway_location(self, strategy): self.ensure_one() res = { - 'qty': self.product_qty, - 'product_product_id': self.product_id.id, - 'product_tmpl_id': self.product_id.product_tmpl_id.id, - 'fixed_location_id': self.location_id.id, - 'putaway_id': strategy.id, + "qty": self.product_qty, + "product_product_id": self.product_id.id, + "product_tmpl_id": self.product_id.product_tmpl_id.id, + "fixed_location_id": self.location_id.id, + "putaway_id": strategy.id, } return res diff --git a/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py b/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py index 1d85db57a..5a25ffe80 100644 --- a/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py +++ b/stock_generate_putaway_from_inventory/tests/test_generate_putaway.py @@ -10,26 +10,33 @@ class TestGeneratePutaway(TransactionCase): def test_generate(self): """Test default methods""" - self.product_10 = self.env.ref('product.product_product_10') - self.product_25 = self.env.ref('product.product_product_25') - inventory = self.env.ref('stock.stock_inventory_0') - self.env['stock.inventory.line'].create({ - 'product_id': self.product_25.id, - 'product_uom_id': self.ref('product.product_uom_unit'), - 'inventory_id': inventory.id, - 'product_qty': 1.0, - 'location_id': self.ref('stock.stock_location_components'), - }) + self.product_10 = self.env.ref("product.product_product_10") + self.product_25 = self.env.ref("product.product_product_25") + inventory = self.env.ref("stock.stock_inventory_0") + self.env["stock.inventory.line"].create( + { + "product_id": self.product_25.id, + "product_uom_id": self.ref("product.product_uom_unit"), + "inventory_id": inventory.id, + "product_qty": 1.0, + "location_id": self.ref("stock.stock_location_components"), + } + ) inventory.generate_putaway_strategy() self.assertEquals( - len(self.product_25.product_putaway_ids), 1, - 'pas le bon nombre de putaway strategy créées') + len(self.product_25.product_putaway_ids), + 1, + "pas le bon nombre de putaway strategy créées", + ) self.assertEquals( self.product_10.product_putaway_ids.fixed_location_id.id, - self.ref('stock.stock_location_components')) + self.ref("stock.stock_location_components"), + ) self.assertEquals( self.product_10.product_putaway_ids.putaway_id.id, - self.ref('stock_putaway_product.product_putaway_per_product_wh')) + self.ref("stock_putaway_product.product_putaway_per_product_wh"), + ) self.assertEquals( self.product_25.product_putaway_ids.fixed_location_id.id, - self.ref('stock.stock_location_14')) + self.ref("stock.stock_location_14"), + )