From 858c163cbed12e3b5fe938e0bc62f142c767e74d Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Thu, 23 Nov 2023 22:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=B0=83=E6=95=B4=E8=B4=A7?= =?UTF-8?q?=E6=9E=B6=E8=B4=A7=E4=BD=8D=E4=B8=BA=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/__manifest__.py | 3 +- sf_warehouse/models/model.py | 115 ++++++++++++- sf_warehouse/security/ir.model.access.csv | 2 +- sf_warehouse/views/shelf_location.xml | 201 ++++++++++++++++++++++ sf_warehouse/views/view.xml | 2 + 5 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 sf_warehouse/views/shelf_location.xml diff --git a/sf_warehouse/__manifest__.py b/sf_warehouse/__manifest__.py index c3cdf682..0f241b90 100644 --- a/sf_warehouse/__manifest__.py +++ b/sf_warehouse/__manifest__.py @@ -13,8 +13,9 @@ 'depends': ['stock', 'web', ], 'data': [ # 'security/group_security.xml', - # 'security/ir.model.access.csv', + 'security/ir.model.access.csv', 'views/view.xml', + 'views/shelf_location.xml', ], 'demo': [ ], diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index cfa097ce..5e83ff1f 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -12,10 +12,13 @@ class SfLocation(models.Model): barcode = fields.Char('Barcode', copy=False, size=15) # 仓库类别(selection:库区、库位、货位) + # location_type = fields.Selection([ + # ('库区', '库区'), + # ('货架', '货架'), + # ('货位', '货位') + # ], string='存储类型') location_type = fields.Selection([ - ('库区', '库区'), - ('货架', '货架'), - ('货位', '货位') + ('库区', '库区') ], string='存储类型') # 库区类型(selection:拣货区、存货区、收货区、退货区、次品区) area_type = fields.Selection([ @@ -25,6 +28,10 @@ class SfLocation(models.Model): ('退货区', '退货区'), ('次品区', '次品区') ], string='库区类型') + # 当前位置 + current_location_id = fields.Many2one('sf.shelf.location', string='当前位置') + # 目的位置 + destination_location_id = fields.Many2one('sf.shelf.location', string='目的位置') # 存储类型(selection:库区、货架) # storage_type = fields.Selection([ # ('库区', '库区'), @@ -207,6 +214,108 @@ class SfLocation(models.Model): # + str(j + 1) +class ShelfLocation(models.Model): + _name = 'sf.shelf.location' + _description = '货架货位' + + name = fields.Char('名称', required=True, size=20) + barcode = fields.Char('编码', copy=False, size=15) + + # 仓库类别(selection:库区、库位、货位) + location_type = fields.Selection([ + ('货架', '货架'), + ('货位', '货位') + ], string='存储类型') + # 绑定库区 + location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')]) + # 产品类别 (关联:product.category) + product_type = fields.Many2many('product.category', string='产品类别') + # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 + channel = fields.Char(string='通道') + direction = fields.Selection([ + ('R', 'R'), + ('L', 'L') + ], string='方向') + shelf_height = fields.Float(string='货架高度(m)') + shelf_layer = fields.Integer(string='货架层数') + layer_capacity = fields.Integer(string='层数容量') + + # 货位独有字段:货位状态、产品(关联产品对象)、产品序列号(关联产品序列号对象) + location_status = fields.Selection([ + ('空闲', '空闲'), + ('占用', '占用'), + ('禁用', '禁用') + ], string='货位状态', default='空闲') + # product_id = fields.Many2one('product.template', string='产品') + product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', readonly=True) + product_sn_id = fields.Many2one('stock.lot', string='产品序列号') + + hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') + hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') + + @api.depends('product_sn_id') + def _compute_product_id(self): + """ + 根据产品序列号,获取产品 + """ + for record in self: + if record.product_sn_id: + record.product_id = record.product_sn_id.product_id + record.location_status = '占用' + else: + record.product_id = False + # record.location_status = '空闲' + + @api.depends('location_type') + def _compute_hide_what(self): + """ + 根据仓库类别,隐藏不需要的字段 + :return: + """ + for record in self: + record.hide_shelf = False + record.hide_location = False + if record.location_type and record.location_type == '货架': + record.hide_shelf = True + elif record.location_type and record.location_type == '货位': + record.hide_location = True + else: + pass + + # 生成货位 + def create_location(self): + """ + 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 + """ + 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.id, + 'location_type': '货位', + 'barcode': self.generate_barcode(i, j), + 'location_status': '空闲' + }) + + def generate_barcode(self, i, j): + """ + 生成货位条码 + """ + # 这里是你生成barcode的代码 + # area_type_barcode = self.location_id.barcode + area_type_barcode = self.barcode + i_str = str(i + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + j_str = str(j + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str + + # def generate_barcode(self, i, j): + # # 这里是你生成barcode的代码 + # area_type_barcode = self.location_id.barcode + # return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + str(i + 1) + '-' + # + str(j + 1) + + class SfProcurementGroup(models.Model): _inherit = 'procurement.group' diff --git a/sf_warehouse/security/ir.model.access.csv b/sf_warehouse/security/ir.model.access.csv index 94ce7d2b..46c1988e 100644 --- a/sf_warehouse/security/ir.model.access.csv +++ b/sf_warehouse/security/ir.model.access.csv @@ -1,4 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_stock_location,stock.location,model_stock_location,base.group_user,1,1,1,1 +access_sf_shelf_location,sf.shelf.location,model_sf_shelf_location,base.group_user,1,1,1,1 diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml new file mode 100644 index 00000000..a7ef00d9 --- /dev/null +++ b/sf_warehouse/views/shelf_location.xml @@ -0,0 +1,201 @@ + + + + + Shelf Location tree + sf.shelf.location + + + + + + + + + + + Shelf Location form + sf.shelf.location + +
+
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 货架货位 + ir.actions.act_window + sf.shelf.location + tree,form + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml index 56ddc19a..93e55dfb 100644 --- a/sf_warehouse/views/view.xml +++ b/sf_warehouse/views/view.xml @@ -32,6 +32,8 @@ + +