diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 4990d233..af4e185a 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -10,22 +10,12 @@ class SfLocation(models.Model): name = fields.Char('Location Name', required=True, size=20) barcode = fields.Char('Barcode', copy=False, required=True, size=15) - # 仓库类别(selection:仓库、库区、库位、货位) + # 仓库类别(selection:库区、库位、货位) location_type = fields.Selection([ - ('仓库', '仓库'), ('库区', '库区'), ('货架', '货架'), ('货位', '货位') ], string='仓库类别') - # 仓库类型(分类:成品库、坯料库、原材料库、刀具库、线边料库、线边刀库) - location_category = fields.Selection([ - ('成品库', '成品库'), - ('坯料库', '坯料库'), - ('原材料库', '原材料库'), - ('刀具库', '刀具库'), - ('线边料库', '线边料库'), - ('线边刀库', '线边刀库') - ], string='仓库类型') # 库区类型(selection:拣货区、存货区、收货区、退货区、次品区) area_type = fields.Selection([ ('拣货区', '拣货区'), @@ -34,6 +24,13 @@ class SfLocation(models.Model): ('退货区', '退货区'), ('次品区', '次品区') ], string='库区类型') + # 存储类型(selection:库区、货架) + storage_type = fields.Selection([ + ('库区', '库区'), + ('货架', '货架') + ], string='存储类型') + # 产品类别 (关联:product.category) + product_type = fields.Many2many('product.category', string='产品类别') # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 channel = fields.Char(string='通道', required=True) direction = fields.Selection([ @@ -64,6 +61,27 @@ class SfLocation(models.Model): hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') + @api.model + def create(self, vals): + """ + 重写create方法,添加自定义的约束 + """ + print('create', vals) + if vals.get('location_id'): + location = self.env['stock.location'].browse(vals.get('location_id')) + if location.storage_type == '库区': + raise UserError('库区不能作为父级仓库') + return super().create(vals) + + @api.onchange('location_id') + def _onchange_location_id(self): + """ + 重写onchange方法,添加自定义的约束 + """ + if self.location_id: + if self.location_id.storage_type == '库区': + raise UserError('库区不能作为父级仓库') + # @api.constrains('shelf_height') # def _check_shelf_height(self): # for record in self: @@ -84,6 +102,9 @@ class SfLocation(models.Model): @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 @@ -153,6 +174,9 @@ class SfLocation(models.Model): # 生成货位 def create_location(self): + """ + 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 + """ if self.location_type == '货架': for i in range(self.shelf_layer): for j in range(self.layer_capacity): @@ -165,8 +189,12 @@ class SfLocation(models.Model): }) def generate_barcode(self, i, j): + """ + 生成货位条码 + """ # 这里是你生成barcode的代码 - area_type_barcode = self.location_id.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 diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml index ba03d4ad..6481fa84 100644 --- a/sf_warehouse/views/view.xml +++ b/sf_warehouse/views/view.xml @@ -30,11 +30,13 @@ + + - - + + @@ -53,7 +55,13 @@