From b045854a632524a5f233599b547c6b7558ab334c Mon Sep 17 00:00:00 2001 From: "qihao.gong@jikimo.com" Date: Fri, 23 Feb 2024 11:58:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 35 ++++++++++++++++++--- sf_warehouse/models/model.py | 1 + sf_warehouse/views/shelf_location.xml | 1 + 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 4703f6f7..f035c5e9 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -296,7 +296,7 @@ class Manufacturing_Connect(http.Controller): logging.info('NCProgDolod error:%s' % e) return json.JSONEncoder().encode(res) - @http.route('/AutoDeviceApi/LocationChange', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/AutoDeviceApi/LocationChange', type='json', auth='none', methods=['GET', 'POST'], csrf=False, cors="*") def LocationChange(self, **kw): """ @@ -309,11 +309,36 @@ class Manufacturing_Connect(http.Controller): res = {'Succeed': True, 'Datas': []} datas = request.httprequest.data ret = json.loads(datas) - if ret: - print(ret) + RfidCode = ret['RfidCode'] + ChangeType = ret['ChangeType'] + OldDeciveId = ret['OldDeciveId'] + OldPosition = ret['OldPosition'] + NewDeciveId = ret['NewDeciveId'] + NewPosition = ret['NewPosition'] + OldDeciveStart = ret['OldDeciveStart'] + OldDeciveEnd = ret['OldDeciveEnd'] + workorder = request.env['mrp.workorder'].sudo().search( + [('rfid_code', '=', RfidCode)], limit=1) + if not workorder: + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未找到该工单'} return json.JSONEncoder().encode(res) - else: - res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'} + old_localtion = request.env['sf.shelf.location'].sudo().search( + [('barcode', '=', OldPosition)], limit=1) + new_localtion = request.env['sf.shelf.location'].sudo().search( + [('barcode', '=', NewPosition)], limit=1) + if not new_localtion: + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该存储位置'} + return json.JSONEncoder().encode(res) + if workorder and old_localtion and new_localtion: + old_localtion.location_status = '空闲' + new_localtion.location_status = '占用' + new_localtion.production_id = workorder.production_id.id + if old_localtion == 'None': + new_localtion.location_status = '占用' + new_localtion.production_id = workorder.production_id.id + # return json.JSONEncoder().encode(res) + # else: + # res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'} except Exception as e: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('LocationChange error:%s' % e) diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 646acd4c..fe7360b4 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -318,6 +318,7 @@ class ShelfLocation(models.Model): current_move_ids = fields.One2many('stock.move.line', 'current_location_id', '当前位置调拨单') destination_move_ids = fields.One2many('stock.move.line', 'destination_location_id', '目标位置调拨单') storage_time = fields.Datetime('入库时间', compute='_compute_location_status') + production_id = fields.Many2one('mrp.production', string='制造订单') @api.depends('location_status') def _compute_location_status(self): diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml index 457efc46..9c3fd678 100644 --- a/sf_warehouse/views/shelf_location.xml +++ b/sf_warehouse/views/shelf_location.xml @@ -153,6 +153,7 @@ + From c726bb614ce2bac46a227d15b147fa84043a89ea Mon Sep 17 00:00:00 2001 From: "qihao.gong@jikimo.com" Date: Fri, 23 Feb 2024 15:31:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BA=93=E5=8C=BA=E4=BF=A1=E6=81=AF=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 14 ++++----- sf_manufacturing/views/mrp_workorder_view.xml | 2 +- sf_warehouse/__manifest__.py | 1 + sf_warehouse/data/ir_cron_data.xml | 14 +++++++++ sf_warehouse/models/__init__.py | 1 + sf_warehouse/models/model.py | 7 +++-- sf_warehouse/models/sync_common.py | 30 +++++++++++++++++++ sf_warehouse/views/shelf_location.xml | 2 -- 8 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 sf_warehouse/data/ir_cron_data.xml create mode 100644 sf_warehouse/models/sync_common.py diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 570116e9..0a5e2d0d 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -320,22 +320,20 @@ class Manufacturing_Connect(http.Controller): workorder = request.env['mrp.workorder'].sudo().search( [('rfid_code', '=', RfidCode)], limit=1) if not workorder: - res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未找到该工单'} + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该工单'} return json.JSONEncoder().encode(res) old_localtion = request.env['sf.shelf.location'].sudo().search( [('barcode', '=', OldPosition)], limit=1) new_localtion = request.env['sf.shelf.location'].sudo().search( [('barcode', '=', NewPosition)], limit=1) if not new_localtion: - res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该存储位置'} + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'} return json.JSONEncoder().encode(res) - if workorder and old_localtion and new_localtion: + if old_localtion: old_localtion.location_status = '空闲' - new_localtion.location_status = '占用' - new_localtion.production_id = workorder.production_id.id - if old_localtion == 'None': - new_localtion.location_status = '占用' - new_localtion.production_id = workorder.production_id.id + old_localtion.production_id = False + new_localtion.location_status = '占用' + new_localtion.production_id = workorder.production_id.id # return json.JSONEncoder().encode(res) # else: # res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'} diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index cf4fa679..15e7fd3d 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -103,7 +103,6 @@ -