# -*- coding: utf-8 -*- import requests import logging import time from odoo import fields, models class AgvSetting(models.Model): _name = 'sf.agv.site' _description = 'agv站点' name = fields.Char('位置编号') owning_region = fields.Char('所属区域') state = fields.Selection([ ('占用', '占用'), ('空闲', '空闲')], string='状态') divide_the_work = fields.Char('主要分工') active = fields.Boolean('有效', default=True) def update_site_state(self): # 调取中控的接驳站接口并修改对应站点的状态 config = self.env['res.config.settings'].get_values() # token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A] headers = {'Authorization': config['center_control_Authorization']} center_control_url = config['center_control_url'] + "/AutoDeviceApi/GetAgvStationState?date=" timestamp = int(time.time()) center_control_url += str(timestamp) logging.info('工件配送-请求中控地址:%s' % center_control_url) try: center_control_r = requests.get(center_control_url, headers=headers, timeout=60) # 设置超时为60秒 ret = center_control_r.json() logging.info('工件配送-请求中控站点信息:%s' % ret) self.env['center_control.interface.log'].sudo().create( {'content': ret, 'name': 'AutoDeviceApi/GetAgvStationState?date=%s' % str(timestamp)}) if ret['Succeed'] is True: datas = ret['Datas'] for item in self: for da in datas: if da['DeviceId'] == item.name: if da['AtHome'] is True: item.state = '占用' else: item.state = '空闲' return True except requests.exceptions.Timeout: logging.error('工件配送-请求中控接口超时') return False except requests.exceptions.RequestException as e: logging.error('工件配送-请求中控接口错误: %s', e) return False class AgvTaskRoute(models.Model): _name = 'sf.agv.task.route' _description = 'agv任务路线' name = fields.Char('名称') type = fields.Selection([ ('F01', '搬运'), ], string='任务类型', default="F01") route_type = fields.Selection([ ('上产线', '上产线'), ('下产线', '下产线'), ('运送空料架', '运送空料架')], string='类型') start_site_id = fields.Many2one('sf.agv.site', '起点接驳站位置编号') end_site_id = fields.Many2one('sf.agv.site', '终点接驳站位置编号') destination_production_line_id = fields.Many2one('sf.production.line', '目的生产线') active = fields.Boolean('有效', default=True) class Center_controlInterfaceLog(models.Model): _name = 'center_control.interface.log' _description = '中控接口调用日志' _order = 'id desc' name = fields.Char('接口名称') content = fields.Char('接口内容') interface_call_date = fields.Datetime("调用时间", default=fields.Datetime.now, readonly=True) active = fields.Boolean('有效', default=True)