货位代码优化

This commit is contained in:
mgw
2023-11-28 17:21:29 +08:00
parent ddad1e9114
commit 685eced709

View File

@@ -212,6 +212,7 @@ class SfLocation(models.Model):
class ShelfLocation(models.Model):
_name = 'sf.shelf.location'
_description = '货架货位'
_order = 'name'
name = fields.Char('名称', required=True, size=20)
barcode = fields.Char('编码', copy=False, size=15)
@@ -290,7 +291,6 @@ class ShelfLocation(models.Model):
else:
pass
# 生成货位
def create_location(self):
"""
当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量
@@ -298,13 +298,17 @@ class ShelfLocation(models.Model):
if self.location_type == '货架':
for i in range(self.shelf_layer):
for j in range(self.layer_capacity):
self.create({
'name': self.name + '-' + str(i + 1) + '' + '-' + str(j + 1) + '位置',
'location_id': self.shelf_location_id.id,
'location_type': '货位',
'barcode': self.generate_barcode(i, j),
'location_status': '空闲',
})
location_name = self.name + '-' + str(i + 1) + '' + '-' + str(j + 1) + '位置'
# 检查是否已经有同名的位置存在
existing_location = self.search([('name', '=', location_name)])
if not existing_location:
self.create({
'name': location_name,
'location_id': self.shelf_location_id.id,
'location_type': '货位',
'barcode': self.generate_barcode(i, j),
'location_status': '空闲',
})
def generate_barcode(self, i, j):
"""