From a7102c81d4656754d0d14cc5e5ae9619820eff24 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Mon, 3 Jun 2024 14:14:04 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E8=B4=A7=E4=BD=8D?= =?UTF-8?q?=E6=89=B9=E6=AC=A1=E6=95=B0=E9=87=8F=E6=A8=A1=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E6=9D=A5=E5=AD=98=E5=82=A8=E8=B4=A7=E4=BD=8D=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E7=9A=84=E6=89=B9=E6=AC=A1=E5=8F=8A=E5=85=B6=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=9B=E5=AE=8C=E6=88=90=E8=AF=A5=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=B4=A7=E4=BD=8D=E4=BA=A7=E5=93=81=E7=9A=84?= =?UTF-8?q?=E5=87=BA=E5=85=A5=E5=BA=93=E8=AE=B0=E5=BD=95=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=96=E5=87=8F=E5=B0=91=E8=B4=A7=E4=BD=8D?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E6=89=B9=E6=AC=A1=E7=9A=84=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/controllers/controllers.py | 60 +++++++++++++++++ sf_warehouse/models/model.py | 67 +++++++++++++++++-- sf_warehouse/security/ir.model.access.csv | 6 ++ sf_warehouse/views/shelf_location.xml | 4 +- 4 files changed, 131 insertions(+), 6 deletions(-) diff --git a/sf_tool_management/controllers/controllers.py b/sf_tool_management/controllers/controllers.py index a524f0bc..04b89836 100644 --- a/sf_tool_management/controllers/controllers.py +++ b/sf_tool_management/controllers/controllers.py @@ -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) diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 94194a1c..91bd5bf9 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -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' diff --git a/sf_warehouse/security/ir.model.access.csv b/sf_warehouse/security/ir.model.access.csv index f981d477..88514fd3 100644 --- a/sf_warehouse/security/ir.model.access.csv +++ b/sf_warehouse/security/ir.model.access.csv @@ -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 diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml index 6c6d5c76..6fca54f1 100644 --- a/sf_warehouse/views/shelf_location.xml +++ b/sf_warehouse/views/shelf_location.xml @@ -175,8 +175,8 @@ - - + +