From 251ab68ea86466d7fc2bb0fdbebba36a726ce5ca Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 8 Oct 2019 15:03:40 +0200 Subject: [PATCH] Add width/depth/height and per-cell size --- .../models/stock_location_tray_type.py | 26 +++++++++++++++++++ stock_location_tray/tests/test_tray_type.py | 12 +++++++++ .../views/stock_location_tray_type_views.xml | 13 ++++++++++ 3 files changed, 51 insertions(+) diff --git a/stock_location_tray/models/stock_location_tray_type.py b/stock_location_tray/models/stock_location_tray_type.py index a2ec2383e..57be763d3 100644 --- a/stock_location_tray/models/stock_location_tray_type.py +++ b/stock_location_tray/models/stock_location_tray_type.py @@ -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: diff --git a/stock_location_tray/tests/test_tray_type.py b/stock_location_tray/tests/test_tray_type.py index c228a9f1f..bb9a8741f 100644 --- a/stock_location_tray/tests/test_tray_type.py +++ b/stock_location_tray/tests/test_tray_type.py @@ -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) diff --git a/stock_location_tray/views/stock_location_tray_type_views.xml b/stock_location_tray/views/stock_location_tray_type_views.xml index 46a187388..a71c58c7a 100644 --- a/stock_location_tray/views/stock_location_tray_type_views.xml +++ b/stock_location_tray/views/stock_location_tray_type_views.xml @@ -24,6 +24,19 @@ + +