Skip to content

Commit

Permalink
Add position z in tray cells
Browse files Browse the repository at this point in the history
  • Loading branch information
damendieta authored and guewen committed Aug 29, 2019
1 parent dd2055a commit 5801a46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions stock_vertical_lift/models/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,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",
)
Expand Down Expand Up @@ -145,6 +145,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')
Expand Down Expand Up @@ -190,10 +194,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):
Expand All @@ -219,12 +223,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,
}
Expand Down
3 changes: 3 additions & 0 deletions stock_vertical_lift/views/stock_location_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<field name="posy" position="attributes">
<attribute name="attrs">{'readonly': [('vertical_lift_kind', '=', 'cell')]}</attribute>
</field>
<field name="posz" position="attributes">
<attribute name="attrs">{'readonly': [('vertical_lift_kind', '=', 'cell')]}</attribute>
</field>
</field>
</record>

Expand Down

0 comments on commit 5801a46

Please sign in to comment.