1、新增货位批次数量模型,用来存储货位产品的批次及其数量;完成该模型根据货位产品的出入库记录自动新增或减少货位产品批次的数量。
This commit is contained in:
@@ -452,9 +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.Many2many('stock.lot', 'shelf_location_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):
|
||||
@@ -464,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 = '禁用'
|
||||
@@ -526,7 +535,16 @@ class ShelfLocation(models.Model):
|
||||
return records
|
||||
|
||||
|
||||
class Sf_stock_move_line(models.Model):
|
||||
class SfShelfLocationLot(models.Model):
|
||||
_name = 'sf.shelf.location.lot'
|
||||
_description = '批次数量'
|
||||
|
||||
shelf_location_id = fields.Many2one('sf.shelf.location', string="货位")
|
||||
lot_id = fields.Many2one('stock.lot', string='批次号')
|
||||
qty = fields.Integer('数量')
|
||||
|
||||
|
||||
class SfStockMoveLine(models.Model):
|
||||
_name = 'stock.move.line'
|
||||
_inherit = ['stock.move.line', 'printing.utils']
|
||||
|
||||
@@ -837,7 +855,7 @@ class Sf_stock_move_line(models.Model):
|
||||
if obj:
|
||||
obj.product_sn_id = record.lot_id.id
|
||||
elif record.product_id.tracking == 'lot':
|
||||
obj.product_sn_ids |= record.lot_id
|
||||
self.put_shelf_location(record)
|
||||
if not obj.product_id:
|
||||
obj.product_id = record.product_id.id
|
||||
else:
|
||||
@@ -859,6 +877,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'
|
||||
|
||||
Reference in New Issue
Block a user