库存货架货位修改基本完成,推送测试

This commit is contained in:
mgw
2023-11-28 16:42:19 +08:00
parent 4d8b463cb3
commit 2c1a101c24
5 changed files with 279 additions and 137 deletions

View File

@@ -185,33 +185,29 @@ class SfLocation(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.id,
'location_type': '货位',
'barcode': self.generate_barcode(i, j),
'location_status': '空闲'
})
pass
# 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)
pass
# # 这里是你生成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
class ShelfLocation(models.Model):
@@ -227,9 +223,12 @@ class ShelfLocation(models.Model):
('货位', '货位')
], string='存储类型')
# 绑定库区
shelf_location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')])
location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')])
# 产品类别 关联product.category
product_type = fields.Many2many('product.category', string='产品类别')
# product_type = fields.Many2many('product.category', string='产品类别')
# picking_product_type = fields.Many2many('stock.picking', string='调拨产品类别', related='location_dest_id.product_type')
# 货架独有字段通道、方向、货架高度m、货架层数、层数容量
channel = fields.Char(string='通道')
direction = fields.Selection([
@@ -253,6 +252,16 @@ class ShelfLocation(models.Model):
hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架')
hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位')
@api.onchange('shelf_location_id')
def _onchange_shelf_location_id(self):
"""
根据货架的所属库区修改货位的所属库区
"""
all_location = self.env['sf.shelf.location'].search([('name', 'ilike', self.name)])
for record in self:
for location in all_location:
location.location_id = record.shelf_location_id.id
@api.depends('product_sn_id')
def _compute_product_id(self):
"""
@@ -264,7 +273,7 @@ class ShelfLocation(models.Model):
record.location_status = '占用'
else:
record.product_id = False
# record.location_status = '空闲'
record.location_status = '空闲'
@api.depends('location_type')
def _compute_hide_what(self):
@@ -292,10 +301,10 @@ class ShelfLocation(models.Model):
for j in range(self.layer_capacity):
self.create({
'name': self.name + '-' + str(i + 1) + '' + '-' + str(j + 1) + '位置',
'location_id': self.id,
'location_id': self.shelf_location_id.id,
'location_type': '货位',
'barcode': self.generate_barcode(i, j),
'location_status': '空闲'
'location_status': '空闲',
})
def generate_barcode(self, i, j):
@@ -309,11 +318,125 @@ class ShelfLocation(models.Model):
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 Sf_stock_move_line(models.Model):
_inherit = 'stock.move.line'
current_location_id = fields.Many2one(
'sf.shelf.location', string='当前货位', compute='_compute_current_location_id', store=True)
# location_dest_id = fields.Many2one('stock.location', string='目标库位')
location_dest_id_product_type = fields.Many2many(related='location_dest_id.product_type')
location_dest_id_value = fields.Integer(compute='_compute_location_dest_id_value', store=True)
# def button_test(self):
# print(self.picking_id.name)
# stock_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
# print(self.picking_id.name)
# print(aa.move_line_ids.lot_id.name)
# # 获取当前的stock.picking对象
# current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
#
# # 获取当前picking的第一个stock.move对象
# current_move = current_picking.move_ids[0] if current_picking.move_ids else False
#
# # 如果存在相关的stock.move对象
# if current_move:
# # 获取源stock.move对象
# origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False
#
# # 从源stock.move对象获取源stock.picking对象
# origin_picking = origin_move.picking_id if origin_move else False
# # 现在origin_picking就是current_picking的上一步
# # 获取目标stock.move对象
# dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False
#
# # 从目标stock.move对象获取目标stock.picking对象
# dest_picking = dest_move.picking_id if dest_move else False
# # 现在dest_picking就是current_picking的下一步
@api.depends('location_id')
def _compute_current_location_id(self):
# for record in self:
# 获取当前的stock.picking对象
current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
# 获取当前picking的第一个stock.move对象
current_move = current_picking.move_ids[0] if current_picking.move_ids else False
# 如果存在相关的stock.move对象
if current_move:
# 获取源stock.move对象
origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False
# 从源stock.move对象获取源stock.picking对象
origin_picking = origin_move.picking_id if origin_move else False
# 现在origin_picking就是current_picking的上一步
# 如果前一个调拨单有目标货位,那么当前调拨单的当前货位就是前一个调拨单的目标货位
if origin_picking:
for i in current_picking.move_line_ids:
for j in origin_picking.move_line_ids:
if j.destination_location_id:
if i.lot_id == j.lot_id:
i.current_location_id = j.destination_location_id
# if origin_picking.move_line_ids.destination_location_id:
# aa = origin_picking.move_line_ids
# bb = origin_picking.move_line_ids.destination_location_id
# record.current_location_id = origin_picking.move_line_ids.destination_location_id
#
# # 获取目标stock.move对象
# dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False
#
# # 从目标stock.move对象获取目标stock.picking对象
# dest_picking = dest_move.picking_id if dest_move else False
# # 现在dest_picking就是current_picking的下一步
# 是一张单据一张单据往下走的,所以这里的目标货位是上一张单据的当前货位,且这样去计算是可以的。
@api.depends('location_dest_id')
def _compute_location_dest_id_value(self):
for record in self:
record.location_dest_id_value = record.location_dest_id.id if record.location_dest_id else False
destination_location_id = fields.Many2one(
'sf.shelf.location', string='目标货位')
@api.onchange('destination_location_id')
def _compute_destination_location_id(self):
for record in self:
shelf_location_obj = self.env['sf.shelf.location'].search(
[('product_sn_id', '=', record.lot_id.id)])
if shelf_location_obj:
shelf_location_obj.product_sn_id = False
# obj = self.env['sf.shelf.location'].search([('location_id', '=',
# self.destination_location_id.id)])
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
obj.product_sn_id = record.lot_id.id
else:
pass
else:
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
obj.product_sn_id = record.lot_id.id
class SfStockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
"""
重写验证方法,当验证时意味着调拨单已经完成,已经移动到了目标货位,所以需要将当前货位的状态改为空闲
"""
res = super(SfStockPicking, self).button_validate()
for line in self.move_line_ids:
if line:
if line.current_location_id:
line.current_location_id.product_sn_id = False
line.current_location_id = False
return res
class SfProcurementGroup(models.Model):