Accept Merge Request #843: (feature/修改机床参数bug -> develop)
Merge Request: 新增获取库区信息定时器,完善库区变更接口 Created By: @龚启豪 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @龚启豪 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/843?initial=true
This commit is contained in:
@@ -307,7 +307,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):
|
||||
"""
|
||||
@@ -320,11 +320,34 @@ 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': '未根据RfidCode找到该工单'}
|
||||
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 old_localtion:
|
||||
old_localtion.location_status = '空闲'
|
||||
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字段'}
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('LocationChange error:%s' % e)
|
||||
|
||||
@@ -103,7 +103,6 @@
|
||||
<xpath expr="//field[@name='state']" position="before">
|
||||
<field name='user_permissions' invisible="1"/>
|
||||
<field name='name' invisible="1"/>
|
||||
<field name='routing_type' invisible="1"/>
|
||||
<field name='is_delivery' invisible="1"/>
|
||||
<button name="button_start" type="object" string="开始" class="btn-success"
|
||||
attrs="{'invisible': ['|', '|', '|','|',('production_state','in', ('draft', 'done',
|
||||
@@ -160,6 +159,7 @@
|
||||
</xpath>
|
||||
<field name="production_id" position="after" invisible="0">
|
||||
<group>
|
||||
<field name='routing_type'/>
|
||||
<field name="date_planned_start" invisible="1"/>
|
||||
<field name="date_planned_finished" invisible="1"/>
|
||||
<!-- <field name="production_id" readonly="1"/>-->
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['stock', 'web', 'sf_base'],
|
||||
'data': [
|
||||
'data/ir_cron_data.xml',
|
||||
'security/sf_stock_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/view.xml',
|
||||
|
||||
14
sf_warehouse/data/ir_cron_data.xml
Normal file
14
sf_warehouse/data/ir_cron_data.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding='UTF-8'?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.cron" id="ir_cron_sf_shelf_location_datasync">
|
||||
<field name="name">定时同步库区信息</field>
|
||||
<field name="model_id" ref="model_sf_shelf_location_datasync"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model._cron_shelf_location_datasync()</field>
|
||||
<field name="interval_number">4</field>
|
||||
<field name="interval_type">hours</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field name="doall" eval="False"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1 +1,2 @@
|
||||
from . import model
|
||||
from . import sync_common
|
||||
|
||||
@@ -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):
|
||||
@@ -397,12 +398,13 @@ class ShelfLocation(models.Model):
|
||||
crea_url = 'https://x24467i973.zicp.fun/AutoDeviceApi/GetLocationInfos'
|
||||
# objs_all = self.env['maintenance.equipment'].search([('id', '=', self.id)])
|
||||
# machine_tool_list = []
|
||||
params = {'DeviceId': 'Cabinet-AL'}
|
||||
r = requests.get(crea_url, params=params, headers=headers)
|
||||
|
||||
r = requests.get(crea_url, headers=headers)
|
||||
ret = r.json()
|
||||
|
||||
print(ret)
|
||||
if ret['Succeed'] == True:
|
||||
return '获取库位信息成功'
|
||||
return ret['Datas']
|
||||
else:
|
||||
raise UserError("该库位无产品")
|
||||
|
||||
|
||||
30
sf_warehouse/models/sync_common.py
Normal file
30
sf_warehouse/models/sync_common.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import json
|
||||
import base64
|
||||
import requests
|
||||
from odoo import models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MrsShelfLocationDataSync(models.Model):
|
||||
_name = 'sf.shelf.location.datasync'
|
||||
_description = '同步库存信息'
|
||||
|
||||
def _cron_shelf_location_datasync(self):
|
||||
try:
|
||||
shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info()
|
||||
for item in shelfinfo:
|
||||
location_id = self.env['sf.shelf.location'].search([('barcode', '=', item['Postion'])], limit=1)
|
||||
if location_id:
|
||||
workorder_id = self.env['mrp.workorder'].search([('rfid_code', '=', item['RfidCode'])], limit=1)
|
||||
if workorder_id:
|
||||
location_id.production_id = workorder_id.production_id.id
|
||||
location_id.location_status = '占用'
|
||||
logging.info('货架已获取信息:%s' % item)
|
||||
except Exception as e:
|
||||
logging.info("捕获错误信息:%s" % e)
|
||||
raise ValidationError("数据错误导致同步失败,请联系管理员")
|
||||
@@ -119,8 +119,6 @@
|
||||
<form string="Shelf Location">
|
||||
<header>
|
||||
|
||||
<button type="object" class="oe_highlight" name='get_sf_shelf_location_info' string="获取货位信息"/>
|
||||
|
||||
<field name="location_status" invisible="1"/>
|
||||
<button string="禁用货位" name="action_location_status_disable" type="object" class="oe_highlight"
|
||||
attrs="{'invisible': [('location_status', '!=', '空闲')]}"/>
|
||||
@@ -153,6 +151,7 @@
|
||||
<field name="product_id"/>
|
||||
<field name="location_status"/>
|
||||
<field name="storage_time" widget="datetime"/>
|
||||
<field name="production_id" readonly="1"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user