[IMP] stock_generate_putaway_from_inventory: black

This commit is contained in:
Kevin Khao
2020-02-27 11:13:25 +01:00
committed by Pierrick Brun
parent 9aa537f275
commit fd8977714c
3 changed files with 52 additions and 40 deletions

View File

@@ -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,
}

View File

@@ -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

View File

@@ -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"),
)