库存模块逻辑修改已完成
This commit is contained in:
@@ -10,22 +10,12 @@ class SfLocation(models.Model):
|
|||||||
name = fields.Char('Location Name', required=True, size=20)
|
name = fields.Char('Location Name', required=True, size=20)
|
||||||
barcode = fields.Char('Barcode', copy=False, required=True, size=15)
|
barcode = fields.Char('Barcode', copy=False, required=True, size=15)
|
||||||
|
|
||||||
# 仓库类别(selection:仓库、库区、库位、货位)
|
# 仓库类别(selection:库区、库位、货位)
|
||||||
location_type = fields.Selection([
|
location_type = fields.Selection([
|
||||||
('仓库', '仓库'),
|
|
||||||
('库区', '库区'),
|
('库区', '库区'),
|
||||||
('货架', '货架'),
|
('货架', '货架'),
|
||||||
('货位', '货位')
|
('货位', '货位')
|
||||||
], string='仓库类别')
|
], string='仓库类别')
|
||||||
# 仓库类型(分类:成品库、坯料库、原材料库、刀具库、线边料库、线边刀库)
|
|
||||||
location_category = fields.Selection([
|
|
||||||
('成品库', '成品库'),
|
|
||||||
('坯料库', '坯料库'),
|
|
||||||
('原材料库', '原材料库'),
|
|
||||||
('刀具库', '刀具库'),
|
|
||||||
('线边料库', '线边料库'),
|
|
||||||
('线边刀库', '线边刀库')
|
|
||||||
], string='仓库类型')
|
|
||||||
# 库区类型(selection:拣货区、存货区、收货区、退货区、次品区)
|
# 库区类型(selection:拣货区、存货区、收货区、退货区、次品区)
|
||||||
area_type = fields.Selection([
|
area_type = fields.Selection([
|
||||||
('拣货区', '拣货区'),
|
('拣货区', '拣货区'),
|
||||||
@@ -34,6 +24,13 @@ class SfLocation(models.Model):
|
|||||||
('退货区', '退货区'),
|
('退货区', '退货区'),
|
||||||
('次品区', '次品区')
|
('次品区', '次品区')
|
||||||
], string='库区类型')
|
], string='库区类型')
|
||||||
|
# 存储类型(selection:库区、货架)
|
||||||
|
storage_type = fields.Selection([
|
||||||
|
('库区', '库区'),
|
||||||
|
('货架', '货架')
|
||||||
|
], string='存储类型')
|
||||||
|
# 产品类别 (关联:product.category)
|
||||||
|
product_type = fields.Many2many('product.category', string='产品类别')
|
||||||
# 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量
|
# 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量
|
||||||
channel = fields.Char(string='通道', required=True)
|
channel = fields.Char(string='通道', required=True)
|
||||||
direction = fields.Selection([
|
direction = fields.Selection([
|
||||||
@@ -64,6 +61,27 @@ class SfLocation(models.Model):
|
|||||||
hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架')
|
hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架')
|
||||||
hide_location = 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')
|
# @api.constrains('shelf_height')
|
||||||
# def _check_shelf_height(self):
|
# def _check_shelf_height(self):
|
||||||
# for record in self:
|
# for record in self:
|
||||||
@@ -84,6 +102,9 @@ class SfLocation(models.Model):
|
|||||||
|
|
||||||
@api.depends('product_sn_id')
|
@api.depends('product_sn_id')
|
||||||
def _compute_product_id(self):
|
def _compute_product_id(self):
|
||||||
|
"""
|
||||||
|
根据产品序列号,获取产品
|
||||||
|
"""
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.product_sn_id:
|
if record.product_sn_id:
|
||||||
record.product_id = record.product_sn_id.product_id
|
record.product_id = record.product_sn_id.product_id
|
||||||
@@ -153,6 +174,9 @@ class SfLocation(models.Model):
|
|||||||
|
|
||||||
# 生成货位
|
# 生成货位
|
||||||
def create_location(self):
|
def create_location(self):
|
||||||
|
"""
|
||||||
|
当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量
|
||||||
|
"""
|
||||||
if self.location_type == '货架':
|
if self.location_type == '货架':
|
||||||
for i in range(self.shelf_layer):
|
for i in range(self.shelf_layer):
|
||||||
for j in range(self.layer_capacity):
|
for j in range(self.layer_capacity):
|
||||||
@@ -165,8 +189,12 @@ class SfLocation(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def generate_barcode(self, i, j):
|
def generate_barcode(self, i, j):
|
||||||
|
"""
|
||||||
|
生成货位条码
|
||||||
|
"""
|
||||||
# 这里是你生成barcode的代码
|
# 这里是你生成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
|
i_str = str(i + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0
|
||||||
j_str = str(j + 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
|
return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str
|
||||||
|
|||||||
@@ -30,11 +30,13 @@
|
|||||||
<field name="channel" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
<field name="channel" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||||
<field name="direction" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
<field name="direction" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||||
<field name="product_sn_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '空闲')]}"/>
|
<field name="product_sn_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '空闲')]}"/>
|
||||||
|
<field name="area_type" attrs="{'invisible': [('hide_area', '=', False)], 'required': [('hide_area', '!=', False)]}"/>
|
||||||
|
|
||||||
|
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="location_category" attrs="{'invisible': [('hide_location_type', '=', False)], 'required': [('hide_location_type', '!=', False)]}"/>
|
<field name="storage_type" attrs="{'invisible': [('hide_area', '=', False)], 'required': [('hide_area', '!=', False)]}"/>
|
||||||
<field name="area_type" attrs="{'invisible': [('hide_area', '=', False)], 'required': [('hide_area', '!=', False)]}"/>
|
<field name="product_type" widget="many2many_tags" attrs="{'invisible': [('hide_area', '=', False)], 'required': [('hide_area', '!=', False)]}"/>
|
||||||
<field name="shelf_height" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
<field name="shelf_height" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||||
<field name="shelf_layer" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
<field name="shelf_layer" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||||
<field name="layer_capacity" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
<field name="layer_capacity" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||||
@@ -53,7 +55,13 @@
|
|||||||
<button string="生成货位" name="create_location" type="object" class="oe_highlight" attrs="{'invisible': [('hide_shelf', '=', False)]}"/>
|
<button string="生成货位" name="create_location" type="object" class="oe_highlight" attrs="{'invisible': [('hide_shelf', '=', False)]}"/>
|
||||||
</header>
|
</header>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath expr="//form/sheet/group[last()]">
|
||||||
|
<notebook position="after" attrs="{'invisible': [('hide_area', '=', False)]}">
|
||||||
|
<page string="库存信息">
|
||||||
|
<field name="quant_ids" widget="one2many_list" context="{'location': active_id}"/>
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user