1、新增货位批次数量模型,用来存储货位产品的批次及其数量;完成该模型根据货位产品的出入库记录自动新增或减少货位产品批次的数量。
This commit is contained in:
@@ -36,3 +36,63 @@ class Manufacturing_Connect(http.Controller):
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('get_functional_tool_groups_Info error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/AutoDeviceApi/ToolInventory', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_functional_tool_inventory_Info(self, **kw):
|
||||
"""
|
||||
功能刀具清单接口
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('get_functional_tool_inventory_Info:%s' % kw)
|
||||
try:
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
# ret = json.loads(ret['result'])
|
||||
logging.info('DeviceId:%s' % ret)
|
||||
tool_inventory = request.env['sf.tool.inventory'].sudo().search([])
|
||||
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
if tool_inventory:
|
||||
for item in tool_inventory:
|
||||
res['Datas'].append({
|
||||
'ToolName': item.name,
|
||||
'GroupName': item.tool_groups_id.name,
|
||||
'Lifetime': item.life_span
|
||||
})
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('get_functional_tool_inventory_Info error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/AutoDeviceApi/ToolEntity', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_functional_tool_entity_Info(self, **kw):
|
||||
"""
|
||||
功能刀具列表接口
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('get_functional_tool_entity_Info:%s' % kw)
|
||||
try:
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
# ret = json.loads(ret['result'])
|
||||
logging.info('DeviceId:%s' % ret)
|
||||
functional_tools = request.env['sf.functional.cutting.tool.entity'].sudo().search([])
|
||||
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
if functional_tools:
|
||||
for item in functional_tools:
|
||||
res['Datas'].append({
|
||||
'Rfid': item.rfid,
|
||||
'ToolName': item.tool_name_id.name,
|
||||
'GroupName': item.tool_groups_id.name,
|
||||
'MaxLifetime': item.max_lifetime_value,
|
||||
'KnifeHandle': item.cutting_tool_cutterhandle_model_id.name
|
||||
})
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('get_functional_tool_entity_Info error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
|
||||
access_sf_shelf_location_group_sf_stock_user_group_sf_stock_user,sf.shelf.location,model_sf_shelf_location,sf_base.group_sf_stock_user,1,0,0,0
|
||||
access_sf_shelf_location_lot_group_sf_stock_user_group_sf_stock_user,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_sf_stock_user,1,0,0,0
|
||||
access_sf_shelf_location_group_sf_stock_manager,sf.shelf.location,model_sf_shelf_location,sf_base.group_sf_stock_manager,1,1,1,0
|
||||
access_sf_shelf_location_lot_group_sf_stock_manager,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_sf_stock_manager,1,1,1,0
|
||||
access_sf_shelf_group_sf_stock_user_group_sf_stock_user,sf.shelf.group.sf.stock.user,model_sf_shelf,sf_base.group_sf_stock_user,1,0,0,0
|
||||
access_sf_shelf_group_sf_stock_manager,sf.shelf.group.sf.stock.manager,model_sf_shelf,sf_base.group_sf_stock_manager,1,1,1,0
|
||||
|
||||
@@ -101,6 +103,7 @@ access_stock_replenish_option_group_sf_stock_user,stock.replenishment.option,sto
|
||||
access_mrp_production_group_sf_stock_user,mrp.production,mrp.model_mrp_production,sf_base.group_sf_stock_user,1,1,1,0
|
||||
|
||||
access_sf_shelf_location_group_plan_dispatch,sf.shelf.location,model_sf_shelf_location,sf_base.group_plan_dispatch,1,0,0,0
|
||||
access_sf_shelf_location_lot_group_plan_dispatch,sf.shelf.location.lot,model_sf_shelf_location_lot,sf_base.group_plan_dispatch,1,0,0,0
|
||||
access_stock_move,stock.move,stock.model_stock_move,sf_base.group_plan_dispatch,1,1,1,0
|
||||
access_stock_picking_group_plan_dispatch,stock.picking,stock.model_stock_picking,sf_base.group_plan_dispatch,1,0,0,0
|
||||
access_stock_lot_group_plan_dispatch,stock.lot,stock.model_stock_lot,sf_base.group_plan_dispatch,1,0,0,0
|
||||
@@ -142,6 +145,9 @@ access_sf_shelf_location_wizard_group_sf_stock_manager,sf_shelf_location_wizard_
|
||||
access_sf_shelf_location_group_sf_tool_user,sf.shelf.location.group_sf_tool_user,model_sf_shelf_location,sf_base.group_sf_tool_user,1,1,0,0
|
||||
access_sf_shelf_group_user,sf.shelf.location.group_user,model_sf_shelf_location,base.group_user,1,1,0,0
|
||||
|
||||
access_sf_shelf_location_lot_group_sf_tool_user,sf.shelf.location.lot.group_sf_tool_user,model_sf_shelf_location_lot,sf_base.group_sf_tool_user,1,1,0,0
|
||||
access_sf_shelf_lot_group_user,sf.shelf.location.lot.group_user,model_sf_shelf_location_lot,base.group_user,1,1,0,0
|
||||
|
||||
|
||||
access_ir_model_group_sf_stock_user,ir_model_group_sf_stock_user,base.model_ir_model,sf_base.group_sf_stock_user,1,1,0,0
|
||||
access_mrp_workorder_group_sf_stock_user,mrp_workorder_group_sf_stock_user,mrp.model_mrp_workorder,sf_base.group_sf_stock_user,1,0,0,0
|
||||
|
||||
|
@@ -175,8 +175,8 @@
|
||||
<field name="product_sn_ids" readonly="1"
|
||||
attrs="{'invisible': [('product_sn_ids', '=', [])]}">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="lot_id"/>
|
||||
<field name="qty"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="product_num" readonly="1"/>
|
||||
|
||||
Reference in New Issue
Block a user