Accept Merge Request #1072: (release/release_1.5 -> develop)

Merge Request: 添加刀具按批次管理

Created By: @禹翔辉
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @马广威
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1072
This commit is contained in:
马广威
2024-06-14 16:21:38 +08:00
committed by Coding
17 changed files with 753 additions and 376 deletions

View File

@@ -452,8 +452,9 @@ class ShelfLocation(models.Model):
# product_id = fields.Many2one('product.template', string='产品')
product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', store=True)
product_sn_id = fields.Many2one('stock.lot', string='产品序列号')
product_sn_ids = fields.One2many('sf.shelf.location.lot', 'shelf_location_id', string='产品批次号')
# 产品数量
product_num = fields.Integer('数量')
product_num = fields.Integer('数量', compute='_compute_number', store=True)
@api.depends('product_num')
def _compute_product_num(self):
@@ -463,6 +464,15 @@ class ShelfLocation(models.Model):
elif record.product_num == 0:
record.location_status = '空闲'
@api.depends('product_sn_ids.qty')
def _compute_number(self):
for item in self:
if item.product_sn_ids:
qty = 0
for product_sn_id in item.product_sn_ids:
qty += product_sn_id.qty
item.product_num = qty
# 修改货位状态为禁用
def action_location_status_disable(self):
self.location_status = '禁用'
@@ -471,7 +481,7 @@ class ShelfLocation(models.Model):
def action_location_status_enable(self):
self.location_status = '空闲'
@api.depends('product_sn_id')
@api.depends('product_sn_id', 'product_sn_ids')
def _compute_product_id(self):
"""
根据产品序列号,获取产品
@@ -484,7 +494,8 @@ class ShelfLocation(models.Model):
record.sudo().product_num = 1
except Exception as e:
print('eeeeeee占用', e)
elif record.product_sn_ids:
return True
else:
try:
record.sudo().product_id = False
@@ -525,7 +536,24 @@ class ShelfLocation(models.Model):
return records
class Sf_stock_move_line(models.Model):
class SfShelfLocationLot(models.Model):
_name = 'sf.shelf.location.lot'
_description = '批次数量'
name = fields.Char('名称', related='lot_id.name')
shelf_location_id = fields.Many2one('sf.shelf.location', string="货位")
lot_id = fields.Many2one('stock.lot', string='批次号')
qty = fields.Integer('数量')
qty_num = fields.Integer('变更数量')
@api.onchange('qty_num')
def _onchange_qty_num(self):
for item in self:
if item.qty_num > item.qty:
raise ValidationError('变更数量不能比库存数量大!!!')
class SfStockMoveLine(models.Model):
_name = 'stock.move.line'
_inherit = ['stock.move.line', 'printing.utils']
@@ -825,15 +853,20 @@ class Sf_stock_move_line(models.Model):
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if record.lot_id:
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
if obj:
obj.product_sn_id = record.lot_id.id
else:
if obj:
obj.product_sn_id = record.lot_id.id
if record.product_id.tracking == 'serial':
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
if obj:
obj.product_sn_id = record.lot_id.id
else:
if obj:
obj.product_sn_id = record.lot_id.id
elif record.product_id.tracking == 'lot':
self.put_shelf_location(record)
if not obj.product_id:
obj.product_id = record.product_id.id
else:
if obj:
obj.product_id = record.product_id.id
@@ -853,6 +886,47 @@ class Sf_stock_move_line(models.Model):
raise ValidationError(
'%s】货位已经被占用,请重新选择!!!' % item.destination_location_id.barcode)
def put_shelf_location(self, vals):
"""
对货位的批量数据进行数量计算
"""
for record in vals:
if record.lot_id and record.product_id.tracking == 'lot':
if record.current_location_id:
location_lot = self.env['sf.shelf.location.lot'].sudo().search(
[('shelf_location_id', '=', record.current_location_id.id), ('lot_id', '=', record.lot_id.id)])
if location_lot:
location_lot.qty -= record.qty_done
if location_lot.qty == 0:
location_lot.unlink()
elif location_lot.qty < 0:
raise ValidationError('%s】货位【%s】批次的【%s】产品数量不足!' % (
record.current_location_id.barcode, record.lot_id.name, record.product_id.name))
else:
raise ValidationError('%s】货位不存在【%s】批次的【%s】产品' % (
record.current_location_id.barcode, record.lot_id.name, record.product_id.name))
if record.destination_location_id:
location_lot = self.env['sf.shelf.location.lot'].sudo().search(
[('shelf_location_id', '=', record.destination_location_id.id),
('lot_id', '=', record.lot_id.id)])
if location_lot:
location_lot.qty += record.qty_done
else:
self.env['sf.shelf.location.lot'].sudo().create({
'shelf_location_id': record.destination_location_id.id,
'lot_id': record.lot_id.id,
'qty': record.qty_done
})
if not record.destination_location_id.product_id:
record.destination_location_id.product_id = record.product_id.id
@api.model_create_multi
def create(self, vals_list):
records = super(SfStockMoveLine, self).create(vals_list)
self.put_shelf_location(records)
return records
class SfStockPicking(models.Model):
_inherit = 'stock.picking'
@@ -916,6 +990,9 @@ class SfStockPicking(models.Model):
if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in (
move.product_id.fixture_material_id.name or ''):
for item in move.move_line_nosuggest_ids:
if item.rfid:
if self.env['stock.lot'].search([('rfid', '=', item.rfid)]):
raise ValidationError('该Rfid【%s】在系统中已经存在,请重新录入!' % item.rfid)
if item.location_dest_id.name == '进货':
if not item.rfid:
raise ValidationError('你需要提供%s的Rfid' % move.product_id.name)