Merge branch refs/heads/develop into refs/heads/hotfix/功能刀具出入库处理
This commit is contained in:
@@ -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,20 +886,83 @@ 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'
|
||||
|
||||
check_in = fields.Char(string='查询是否为入库单', compute='_check_is_in')
|
||||
|
||||
def batch_stock_move(self):
|
||||
"""
|
||||
批量调拨,非就绪状态的会被忽略,完成后有通知提示
|
||||
"""
|
||||
for record in self:
|
||||
if record.state != 'assigned':
|
||||
continue
|
||||
record.action_set_quantities_to_reservation()
|
||||
record.button_validate()
|
||||
|
||||
notification_message = '批量调拨完成!请注意,状态非就绪的单据会被忽略'
|
||||
return {
|
||||
'effect': {
|
||||
'fadeout': 'fast',
|
||||
'message': notification_message,
|
||||
'img_url': '/web/image/%s/%s/image_1024' % (
|
||||
self.create_uid._name, self.create_uid.id) if 0 else '/web/static/img/smile.svg',
|
||||
'type': 'rainbow_man',
|
||||
}
|
||||
}
|
||||
|
||||
@api.depends('name')
|
||||
def _check_is_in(self):
|
||||
"""
|
||||
判断是否为出库单
|
||||
"""
|
||||
if self.name:
|
||||
is_check_in = self.name.split('/')
|
||||
self.check_in = is_check_in[1]
|
||||
for record in self:
|
||||
if record.name:
|
||||
is_check_in = record.name.split('/')
|
||||
record.check_in = is_check_in[1]
|
||||
|
||||
def button_validate(self):
|
||||
"""
|
||||
@@ -894,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)
|
||||
|
||||
@@ -20,7 +20,7 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
paired_data = list(zip(my_data, their_data))
|
||||
return paired_data
|
||||
|
||||
shelf_1_obj = self.env['sf.shelf'].search([('name', '=', '一号线边刀架')], limit=1)
|
||||
shelf_1_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-一号线边刀架')], limit=1)
|
||||
tool_location_objs_1 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_1_obj.id)], order='id')
|
||||
|
||||
location_codes_1 = [location.barcode for location in tool_location_objs_1]
|
||||
@@ -32,7 +32,7 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
aligned_data_1 = align_data(location_codes_1, their_data_1)
|
||||
|
||||
# 2
|
||||
shelf_2_obj = self.env['sf.shelf'].search([('name', '=', '二号线边刀架')], limit=1)
|
||||
shelf_2_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-二号线边刀架')], limit=1)
|
||||
tool_location_objs_2 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_2_obj.id)], order='id')
|
||||
|
||||
location_codes_2 = [location.barcode for location in tool_location_objs_2]
|
||||
@@ -44,7 +44,7 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
aligned_data_2 = align_data(location_codes_2, their_data_2)
|
||||
|
||||
# 4
|
||||
shelf_4_obj = self.env['sf.shelf'].search([('name', '=', '一号线边料架')], limit=1)
|
||||
shelf_4_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-一号线边料架')], limit=1)
|
||||
tool_location_objs_4 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_4_obj.id)], order='id')
|
||||
|
||||
location_codes_4 = [location.barcode for location in tool_location_objs_4]
|
||||
@@ -56,7 +56,7 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
aligned_data_4 = align_data(location_codes_4, their_data_4)
|
||||
|
||||
# 3
|
||||
shelf_3_obj = self.env['sf.shelf'].search([('name', '=', '一号线边料架')], limit=1)
|
||||
shelf_3_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-二号线边料架')], limit=1)
|
||||
tool_location_objs_3 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_3_obj.id)], order='id')
|
||||
|
||||
location_codes_3 = [location.barcode for location in tool_location_objs_3]
|
||||
@@ -68,7 +68,7 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
aligned_data_3 = align_data(location_codes_3, their_data_3)
|
||||
|
||||
# 5
|
||||
shelf_5_obj = self.env['sf.shelf'].search([('name', '=', '一号线边料架')], limit=1)
|
||||
shelf_5_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-三号线边料架')], limit=1)
|
||||
tool_location_objs_5 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_5_obj.id)], order='id')
|
||||
|
||||
location_codes_5 = [location.barcode for location in tool_location_objs_5]
|
||||
|
||||
Reference in New Issue
Block a user