From 685eced709798724b1c10c0817d9be30c5d3565b Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Tue, 28 Nov 2023 17:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A7=E4=BD=8D=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/models/model.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 07e98c5a..4bb84299 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -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): """