库存模块逻辑修改已完成

This commit is contained in:
mgw
2023-07-13 16:09:28 +08:00
parent 58b9ea404b
commit f9c63b69a1
2 changed files with 51 additions and 15 deletions

View File

@@ -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