diff --git a/stock_vertical_lift/models/stock_location.py b/stock_vertical_lift/models/stock_location.py
index e764683304d2..c7f53c54d92f 100644
--- a/stock_vertical_lift/models/stock_location.py
+++ b/stock_vertical_lift/models/stock_location.py
@@ -37,8 +37,8 @@ class StockLocation(models.Model):
default=lambda self: self._default_cell_name_format(),
help="Cells sub-locations generated in a tray will be named"
" after this format. Replacement fields between curly braces are used"
- " to inject positions. {x} will be replaced by the x position and"
- " {y} by the y position. Complex formatting (such as padding, ...)"
+ " to inject positions. {x}, {y}, and {z} will be replaced by their"
+ " corresponding position. Complex formatting (such as padding, ...)"
" can be done using the format specification at "
" https://docs.python.org/2/library/string.html#formatstrings",
)
@@ -144,6 +144,10 @@ def write(self, vals):
super(StockLocation, location).write(vals)
if trays_to_update:
self._update_tray_sublocations()
+ elif 'posz' in vals and location.vertical_lift_kind == 'tray':
+ # On initial generation (when tray_to_update is true),
+ # the sublocations are already generated with the pos z.
+ location.child_ids.write({'posz': vals['posz']})
return True
@api.constrains('active')
@@ -189,10 +193,10 @@ def _tray_cell_matrix(self):
cells[cell.posy - 1][cell.posx - 1] = 1
return cells
- def _format_tray_sublocation_name(self, x, y):
+ def _format_tray_sublocation_name(self, x, y, z):
template = self.cell_name_format or self._default_cell_name_format()
# using format_map allow to have missing replacement strings
- return template.format_map(defaultdict(str, x=x, y=y))
+ return template.format_map(defaultdict(str, x=x, y=y, z=z))
@api.multi
def _update_tray_sublocations(self):
@@ -218,12 +222,17 @@ def _update_tray_sublocations(self):
continue
# create accepts several records now
+ posz = location.posz or 0
for row in range(1, tray_type.rows + 1):
for col in range(1, tray_type.cols + 1):
+ cell_name = location._format_tray_sublocation_name(
+ col, row, posz
+ )
subloc_values = {
- 'name': location._format_tray_sublocation_name(col, row),
+ 'name': cell_name,
'posx': col,
'posy': row,
+ 'posz': posz,
'location_id': location.id,
'company_id': location.company_id.id,
}
diff --git a/stock_vertical_lift/views/stock_location_views.xml b/stock_vertical_lift/views/stock_location_views.xml
index 18016973e3f9..8ebb83aa8d29 100644
--- a/stock_vertical_lift/views/stock_location_views.xml
+++ b/stock_vertical_lift/views/stock_location_views.xml
@@ -32,6 +32,9 @@
{'readonly': [('vertical_lift_kind', '=', 'cell')]}
+
+ {'readonly': [('vertical_lift_kind', '=', 'cell')]}
+