Add width/depth/height and per-cell size

This commit is contained in:
Guewen Baconnier
2019-10-08 15:03:40 +02:00
committed by Hai Lang
parent 4ad48463c2
commit 251ab68ea8
3 changed files with 51 additions and 0 deletions

View File

@@ -14,12 +14,38 @@ class StockLocationTrayType(models.Model):
code = fields.Char(required=True)
rows = fields.Integer(required=True)
cols = fields.Integer(required=True)
width = fields.Integer(help="Width of the tray in mm")
depth = fields.Integer(help="Depth of the tray in mm")
height = fields.Integer(help="Height of the tray in mm")
width_per_cell = fields.Float(compute='_compute_width_per_cell')
depth_per_cell = fields.Float(compute='_compute_depth_per_cell')
active = fields.Boolean(default=True)
tray_matrix = Serialized(compute="_compute_tray_matrix")
location_ids = fields.One2many(
comodel_name="stock.location", inverse_name="tray_type_id"
)
@api.depends("width", "cols")
def _compute_width_per_cell(self):
for record in self:
width = record.width
if not width:
record.width_per_cell = 0.
continue
record.width_per_cell = width / record.cols
@api.depends("depth", "rows")
def _compute_depth_per_cell(self):
for record in self:
depth = record.depth
if not depth:
record.depth_per_cell = 0.
continue
record.depth_per_cell = depth / record.rows
@api.depends("rows", "cols")
def _compute_tray_matrix(self):
for record in self:

View File

@@ -70,3 +70,15 @@ class TestLocationTrayType(LocationTrayTypeCase):
# we can modify size of unused ones
self.unused_tray_type.rows = 10
self.unused_tray_type.cols = 10
def test_width_per_cell(self):
tray_type = self.used_tray_type
tray_type.cols = 10
tray_type.width = 120
self.assertEqual(tray_type.width_per_cell, 12)
def test_depth_per_cell(self):
tray_type = self.used_tray_type
tray_type.rows = 10
tray_type.depth = 120
self.assertEqual(tray_type.depth_per_cell, 12)

View File

@@ -24,6 +24,19 @@
<field name="rows"/>
<field name="cols"/>
</group>
<group string="Sizes" name="size">
<label for="width"/>
<div>
<field name="width"/> mm /
<field name="width_per_cell"/> mm per cell
</div>
<label for="depth"/>
<div>
<field name="depth"/> mm /
<field name="depth_per_cell"/> mm per cell
</div>
<field name="height"/>
</group>
<group string="Disposition" name="disposition">
<field name="tray_matrix"
widget="location_tray_matrix"