1、优化刀具、夹具同步接口;关闭刀具同步接口的实时调用;

This commit is contained in:
yuxianghui
2024-05-21 09:23:47 +08:00
parent dc381faae6
commit 1b6ca90bd4
7 changed files with 390 additions and 373 deletions

View File

@@ -5,8 +5,8 @@
<field name="model_id" ref="model_sf_tool_datasync"/> <field name="model_id" ref="model_sf_tool_datasync"/>
<field name="state">code</field> <field name="state">code</field>
<field name="code">model._cron_tool_datasync_all()</field> <field name="code">model._cron_tool_datasync_all()</field>
<field name="interval_number">1</field> <field name="interval_number">12</field>
<field name="interval_type">days</field> <field name="interval_type">hours</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
</record> </record>
</odoo> </odoo>

View File

@@ -1,6 +1,7 @@
import json import json
import base64 import base64
import requests import requests
import logging
from odoo import models, api from odoo import models, api
from odoo.addons.sf_base.commons.common import Common from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import UserError from odoo.exceptions import UserError
@@ -10,30 +11,36 @@ class StockLot(models.Model):
_inherit = 'stock.lot' _inherit = 'stock.lot'
_description = '夹具物料序列号注册' _description = '夹具物料序列号注册'
def enroll_fixture_material_stock(self): def sync_enroll_fixture_material_stock_all(self):
logging.info("调用 sync_enroll_fixture_material_stock_all 同步接口")
sf_sync_config = self.env['res.config.settings'].get_values() sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + "/api/fixture_material_stock/create" str_url = sf_sync_config['sf_url'] + "/api/fixture_material_stock/create"
objs_all = self.env['stock.lot'].search([('id', '=', self.id)]) product_ids = self.env['product.product'].sudo().search([('categ_type', '=', '夹具')]).ids
objs_all = self.env['stock.lot'].search([('rfid', '!=', False), ('product_id', 'in', product_ids)])
fixture_material_stock_list = [] fixture_material_stock_list = []
if objs_all: try:
for item in objs_all: if objs_all:
val = { for item in objs_all:
'name': item.name, val = {
'tool_material_status': item.tool_material_status, 'name': item.name,
'location': [] if not item.quant_ids else item.quant_ids[-1].location_id.name, 'tool_material_status': item.tool_material_status,
'fixture_material_search_id': item.fixture_material_search_id.id, 'location': [] if not item.quant_ids else item.quant_ids[-1].location_id.name,
} 'fixture_material_search_id': item.fixture_material_search_id.id,
fixture_material_stock_list.append(val) }
kw = json.dumps(fixture_material_stock_list, ensure_ascii=False) fixture_material_stock_list.append(val)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) kw = json.dumps(fixture_material_stock_list, ensure_ascii=False)
ret = r.json() r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
if ret.get('code') == 200: ret = r.json()
return '夹具物料序列号注册成功' if ret.get('code') == 200:
else: logging.info("夹具物料序列号每日同步成功")
raise UserError("没有注册夹具物料序列号信息") return '夹具物料序列号注册成功'
else:
logging.info("没有注册夹具物料序列号信息")
except Exception as e:
logging.info("夹具物料序列号同步失败:%s" % e)
class FixtureMaterialSearch(models.Model): class FixtureMaterialSearch(models.Model):
@@ -42,41 +49,46 @@ class FixtureMaterialSearch(models.Model):
crea_url = "/api/fixture_material/create" crea_url = "/api/fixture_material/create"
def enroll_fixture_material(self): def sync_enroll_fixture_material_all(self):
logging.info("调用 sync_enroll_fixture_material_all 同步接口")
sf_sync_config = self.env['res.config.settings'].get_values() sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.search([('id', '=', self.id)]) objs_all = self.search([])
fixture_material_list = [] fixture_material_list = []
if objs_all: try:
for obj in objs_all: if objs_all:
val = { for obj in objs_all:
'name': obj.name, val = {
'id': obj.id, 'name': obj.name,
'fixture_material_code': obj.fixture_material_id.code, 'id': obj.id,
'fixture_model_code': obj.fixture_model_id.code, 'fixture_material_code': obj.fixture_material_id.code,
'specification_name': obj.specification_fixture_id.name, 'fixture_model_code': obj.fixture_model_id.code,
'image': '' if not obj.image else base64.b64encode(obj.image).decode('utf-8'), 'specification_name': obj.specification_fixture_id.name,
'number': obj.number, 'image': '' if not obj.image else base64.b64encode(obj.image).decode('utf-8'),
'usable_num': obj.usable_num, 'number': obj.number,
'have_been_used_num': obj.have_been_used_num, 'usable_num': obj.usable_num,
'scrap_num': obj.scrap_num 'have_been_used_num': obj.have_been_used_num,
} 'scrap_num': obj.scrap_num
fixture_material_list.append(val) }
kw = json.dumps(fixture_material_list, ensure_ascii=False) fixture_material_list.append(val)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) kw = json.dumps(fixture_material_list, ensure_ascii=False)
ret = r.json() r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
if ret.get('code') == 200: ret = r.json()
return '夹具物料注册成功' if ret.get('code') == 200:
else: logging.info("夹具物料每日同步成功")
raise UserError("没有注册夹具物料信息") return '夹具物料注册成功'
else:
logging.info("没有注册夹具物料信息")
except Exception as e:
logging.info("夹具物料同步失败:%s" % e)
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(FixtureMaterialSearch, self).create(vals_list) # records = super(FixtureMaterialSearch, self).create(vals_list)
for record in records: # for record in records:
if record: # if record:
record.enroll_fixture_material() # record.enroll_fixture_material()
return records # return records

View File

@@ -33,23 +33,26 @@ def get_suitable_coolant_names(item):
class ToolDatasync(models.Model): class ToolDatasync(models.Model):
_name = 'sf.tool.datasync' _name = 'sf.tool.datasync'
_description = '定时同步所有刀具' _description = '定时同步所有刀具、夹具'
def _cron_tool_datasync_all(self): def _cron_tool_datasync_all(self):
try: try:
self.env['stock.lot'].sudo().sync_enroll_tool_material_stock_all() self.env['stock.lot'].sudo().sync_enroll_tool_material_stock_all()
logging.info("刀具物料序列号每日同步成功")
self.env['stock.lot'].sudo().sync_enroll_fixture_material_stock_all()
self.env['sf.tool.material.search'].sudo().sync_enroll_tool_material_all() self.env['sf.tool.material.search'].sudo().sync_enroll_tool_material_all()
logging.info("刀具物料每日同步成功")
self.env['sf.fixture.material.search'].sudo().sync_enroll_fixture_material_all()
self.env['sf.functional.cutting.tool.entity'].sudo().esync_enroll_functional_tool_entity_all() self.env['sf.functional.cutting.tool.entity'].sudo().esync_enroll_functional_tool_entity_all()
logging.info("功能刀具列表每日同步成功") logging.info("已全部同步完成!!!")
self.env['sf.functional.tool.warning'].sudo().sync_enroll_functional_tool_warning_all() # self.env['sf.functional.tool.warning'].sudo().sync_enroll_functional_tool_warning_all()
logging.info("功能刀具预警每日同步成功") # logging.info("功能刀具预警每日同步成功")
self.env['stock.move.line'].sudo().sync_enroll_functional_tool_move_all() # self.env['stock.move.line'].sudo().sync_enroll_functional_tool_move_all()
logging.info("功能刀具出入库记录每日同步成功") # logging.info("功能刀具出入库记录每日同步成功")
self.env[ # self.env['sf.real.time.distribution.of.functional.tools'].sudo().sync_enroll_functional_tool_real_time_distribution_all()
'sf.real.time.distribution.of.functional.tools'].sudo().sync_enroll_functional_tool_real_time_distribution_all() # logging.info("功能刀具安全库存每日同步成功")
logging.info("功能刀具安全库存每日同步成功")
except Exception as e: except Exception as e:
logging.info("捕获错误信息:%s" % e) logging.info("捕获错误信息:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员") raise ValidationError("数据错误导致同步失败,请联系管理员")
@@ -59,24 +62,25 @@ class StockLot(models.Model):
_inherit = 'stock.lot' _inherit = 'stock.lot'
_description = '刀具物料序列号注册' _description = '刀具物料序列号注册'
def enroll_tool_material_stock(self): # def enroll_tool_material_stock(self):
logging.info('调用刀具物料序列号注册接口: enroll_tool_material_stock()') # logging.info('调用刀具物料序列号注册接口: enroll_tool_material_stock()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + "/api/tool_material_stock/create" # str_url = sf_sync_config['sf_url'] + "/api/tool_material_stock/create"
objs_all = self.env['stock.lot'].search([('id', '=', self.id), ('active', 'in', [True, False])]) # objs_all = self.env['stock.lot'].search([('id', '=', self.id), ('active', 'in', [True, False])])
self._get_sync_stock_lot(objs_all, str_url, token, headers) # self._get_sync_stock_lot(objs_all, str_url, token, headers)
def sync_enroll_tool_material_stock_all(self): def sync_enroll_tool_material_stock_all(self):
logging.info('调用刀具物料序列号注册接口: sync_enroll_tool_material_stock_all()') logging.info('调用 sync_enroll_tool_material_stock_all 同步接口')
sf_sync_config = self.env['res.config.settings'].get_values() sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + "/api/tool_material_stock/create" str_url = sf_sync_config['sf_url'] + "/api/tool_material_stock/create"
objs_all = self.env['stock.lot'].search([('rfid', '!=', False)]) product_ids = self.env['product.product'].sudo().search([('categ_type', '=', '刀具')]).ids
objs_all = self.env['stock.lot'].search([('rfid', '!=', False), ('product_id', 'in', product_ids)])
self._get_sync_stock_lot(objs_all, str_url, token, headers) self._get_sync_stock_lot(objs_all, str_url, token, headers)
def _get_sync_stock_lot(self, objs_all, str_url, token, headers): def _get_sync_stock_lot(self, objs_all, str_url, token, headers):
@@ -95,11 +99,12 @@ class StockLot(models.Model):
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() ret = r.json()
if ret.get('code') == 200: if ret.get('code') == 200:
return '刀具物料序列号注册成功' logging.info("刀具物料序列号每日同步成功")
return '刀具(夹具)物料序列号注册成功'
else: else:
logging.info("没有注册刀具物料序列号信息") logging.info("没有刀具物料序列号信息")
except Exception as e: except Exception as e:
logging.info("捕获错误信息:%s" % e) logging.info("刀具物料序列号同步失败:%s" % e)
class ToolMaterial(models.Model): class ToolMaterial(models.Model):
@@ -108,18 +113,18 @@ class ToolMaterial(models.Model):
crea_url = '/api/tool_material/create' crea_url = '/api/tool_material/create'
def enroll_tool_material(self): # def enroll_tool_material(self):
logging.info('调用刀具物料注册接口: enroll_tool_material()') # logging.info('调用刀具物料注册接口: enroll_tool_material()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.search([('id', '=', self.id)]) # objs_all = self.search([('id', '=', self.id)])
self._get_sync_tool_material_search(objs_all, str_url, token, headers) # self._get_sync_tool_material_search(objs_all, str_url, token, headers)
def sync_enroll_tool_material_all(self): def sync_enroll_tool_material_all(self):
logging.info('调用刀具物料注册接口: sync_enroll_tool_material_all()') logging.info('调用 sync_enroll_tool_material_all 同步接口')
sf_sync_config = self.env['res.config.settings'].get_values() sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] sf_secret_key = sf_sync_config['sf_secret_key']
@@ -150,19 +155,20 @@ class ToolMaterial(models.Model):
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() ret = r.json()
if ret.get('code') == 200: if ret.get('code') == 200:
logging.info("刀具物料每日同步成功")
return '刀具物料注册成功' return '刀具物料注册成功'
else: else:
logging.info('没有注册刀具物料信息') logging.info('没有注册刀具物料信息')
except Exception as e: except Exception as e:
logging.info("捕获错误信息:%s" % e) logging.info("刀具物料同步失败:%s" % e)
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(ToolMaterial, self).create(vals_list) # records = super(ToolMaterial, self).create(vals_list)
for record in records: # for record in records:
if record: # if record:
record.enroll_tool_material() # record.enroll_tool_material()
return records # return records
class FunctionalCuttingToolEntity(models.Model): class FunctionalCuttingToolEntity(models.Model):
@@ -172,18 +178,18 @@ class FunctionalCuttingToolEntity(models.Model):
crea_url = "/api/functional_tool_entity/create" crea_url = "/api/functional_tool_entity/create"
# 注册同步功能刀具列表 # 注册同步功能刀具列表
def enroll_functional_tool_entity(self): # def enroll_functional_tool_entity(self):
logging.info('调用功能刀具列表注册接口: enroll_functional_tool_entity()') # logging.info('调用功能刀具列表注册接口: enroll_functional_tool_entity()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['sf.functional.cutting.tool.entity'].search([('id', '=', self.id)]) # objs_all = self.env['sf.functional.cutting.tool.entity'].search([('id', '=', self.id)])
self._get_sync_functional_cutting_tool_entity(objs_all, str_url, token, headers) # self._get_sync_functional_cutting_tool_entity(objs_all, str_url, token, headers)
def esync_enroll_functional_tool_entity_all(self): def esync_enroll_functional_tool_entity_all(self):
logging.info('调用功能刀具列表注册接口: esync_enroll_functional_tool_entity_all()') logging.info('调用 esync_enroll_functional_tool_entity_all 同步接口')
sf_sync_config = self.env['res.config.settings'].get_values() sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] sf_secret_key = sf_sync_config['sf_secret_key']
@@ -242,256 +248,257 @@ class FunctionalCuttingToolEntity(models.Model):
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() ret = r.json()
if ret.get('code') == 200: if ret.get('code') == 200:
logging.info("功能刀具列表每日同步成功")
return "功能刀具注册成功" return "功能刀具注册成功"
else: else:
logging.info('没有注册功能刀具信息') logging.info('没有注册功能刀具信息')
except Exception as e: except Exception as e:
logging.info("捕获错误信息:%s" % e) logging.info("功能刀具同步失败:%s" % e)
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(FunctionalCuttingToolEntity, self).create(vals_list) # records = super(FunctionalCuttingToolEntity, self).create(vals_list)
for record in records: # for record in records:
if record: # if record:
record.enroll_functional_tool_entity() # record.enroll_functional_tool_entity()
return records # return records
def write(self, vals): # def write(self, vals):
res = super().write(vals) # res = super().write(vals)
if vals.get('current_location'): # if vals.get('current_location'):
self.enroll_functional_tool_entity() # self.enroll_functional_tool_entity()
return res # return res
#
class FunctionalToolWarning(models.Model): # class FunctionalToolWarning(models.Model):
_inherit = 'sf.functional.tool.warning' # _inherit = 'sf.functional.tool.warning'
_description = '功能刀具预警注册' # _description = '功能刀具预警注册'
#
crea_url = "/api/functional_tool_warning/create" # crea_url = "/api/functional_tool_warning/create"
#
# 注册同步功能刀具预警 # # 注册同步功能刀具预警
def enroll_functional_tool_warning(self): # def enroll_functional_tool_warning(self):
logging.info('调用功能刀具预警注册接口: enroll_functional_tool_warning()') # logging.info('调用功能刀具预警注册接口: enroll_functional_tool_warning()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['sf.functional.tool.warning'].search([('id', '=', self.id)]) # objs_all = self.env['sf.functional.tool.warning'].search([('id', '=', self.id)])
self.get_sync_functional_tool_warning(objs_all, str_url, token, headers) # self.get_sync_functional_tool_warning(objs_all, str_url, token, headers)
#
def sync_enroll_functional_tool_warning_all(self): # def sync_enroll_functional_tool_warning_all(self):
logging.info('调用功能刀具预警注册接口: sync_enroll_functional_tool_warning_all()') # logging.info('调用功能刀具预警注册接口: sync_enroll_functional_tool_warning_all()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['sf.functional.tool.warning'].search([]) # objs_all = self.env['sf.functional.tool.warning'].search([])
self.get_sync_functional_tool_warning(objs_all, str_url, token, headers) # self.get_sync_functional_tool_warning(objs_all, str_url, token, headers)
#
def get_sync_functional_tool_warning(self, objs_all, str_url, token, headers): # def get_sync_functional_tool_warning(self, objs_all, str_url, token, headers):
tool_warning_list = [] # tool_warning_list = []
try: # try:
if objs_all: # if objs_all:
for item in objs_all: # for item in objs_all:
val = { # val = {
'id': item.id, # 'id': item.id,
'name': item.name, # 'name': item.name,
'code': item.code, # 'code': item.code,
'rfid': item.rfid, # 'rfid': item.rfid,
'tool_groups_name': item.tool_groups_id.name, # 'tool_groups_name': item.tool_groups_id.name,
'production_line': item.production_line_id.name, # 'production_line': item.production_line_id.name,
'machine_tool_id': item.maintenance_equipment_id.code, # 'machine_tool_id': item.maintenance_equipment_id.code,
'machine_tool_code': item.machine_tool_code, # 'machine_tool_code': item.machine_tool_code,
'cutter_spacing_code': item.cutter_spacing_code_id.code, # 'cutter_spacing_code': item.cutter_spacing_code_id.code,
'functional_tool_name': item.name, # 'functional_tool_name': item.name,
'barcode': item.barcode_id.name, # 'barcode': item.barcode_id.name,
'mrs_cutting_tool_type_code': item.mrs_cutting_tool_type_id.code, # 'mrs_cutting_tool_type_code': item.mrs_cutting_tool_type_id.code,
'diameter': item.diameter, # 'diameter': item.diameter,
'knife_tip_r_angle': item.knife_tip_r_angle, # 'knife_tip_r_angle': item.knife_tip_r_angle,
'install_tool_time': item.install_tool_time.strftime('%Y-%m-%d %H:%M:%S'), # 'install_tool_time': item.install_tool_time.strftime('%Y-%m-%d %H:%M:%S'),
'on_board_time': item.on_board_time.strftime('%Y-%m-%d %H:%M:%S'), # 'on_board_time': item.on_board_time.strftime('%Y-%m-%d %H:%M:%S'),
'max_lifetime_value': item.max_lifetime_value, # 'max_lifetime_value': item.max_lifetime_value,
'alarm_value': item.alarm_value, # 'alarm_value': item.alarm_value,
'used_value': item.used_value, # 'used_value': item.used_value,
'functional_tool_status': item.functional_tool_status, # 'functional_tool_status': item.functional_tool_status,
'alarm_time': item.alarm_time.strftime('%Y-%m-%d %H:%M:%S'), # 'alarm_time': item.alarm_time.strftime('%Y-%m-%d %H:%M:%S'),
'dispose_user': item.dispose_user, # 'dispose_user': item.dispose_user,
'dispose_time': item.dispose_time, # 'dispose_time': item.dispose_time,
'dispose_func': item.dispose_func, # 'dispose_func': item.dispose_func,
} # }
tool_warning_list.append(val) # tool_warning_list.append(val)
kw = json.dumps(tool_warning_list, ensure_ascii=False) # kw = json.dumps(tool_warning_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) # r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() # ret = r.json()
if ret.get('code') == 200: # if ret.get('code') == 200:
return "功能刀具预警注册成功" # return "功能刀具预警注册成功"
else: # else:
logging.info('没有注册功能刀具预警信息') # logging.info('没有注册功能刀具预警信息')
except Exception as e: # except Exception as e:
logging.info("捕获错误信息:%s" % e) # logging.info("捕获错误信息:%s" % e)
#
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(FunctionalToolWarning, self).create(vals_list) # records = super(FunctionalToolWarning, self).create(vals_list)
for record in records: # for record in records:
if record: # if record:
record.enroll_functional_tool_warning() # record.enroll_functional_tool_warning()
return records # return records
#
#
class StockMoveLine(models.Model): # class StockMoveLine(models.Model):
_inherit = 'stock.move.line' # _inherit = 'stock.move.line'
_description = '功能刀具出入库记录注册' # _description = '功能刀具出入库记录注册'
#
crea_url = "/api/functional_tool_move/create" # crea_url = "/api/functional_tool_move/create"
#
# 注册同步功能刀具出入库记录 # # 注册同步功能刀具出入库记录
def enroll_functional_tool_move(self): # def enroll_functional_tool_move(self):
logging.info('调用功能刀具出入库记录注册接口: enroll_functional_tool_move()') # logging.info('调用功能刀具出入库记录注册接口: enroll_functional_tool_move()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['stock.move.line'].search([('id', '=', self.id), ('functional_tool_name_id', '!=', False)]) # objs_all = self.env['stock.move.line'].search([('id', '=', self.id), ('functional_tool_name_id', '!=', False)])
self.get_sync_stock_move_line(objs_all, str_url, token, headers) # self.get_sync_stock_move_line(objs_all, str_url, token, headers)
#
def sync_enroll_functional_tool_move_all(self): # def sync_enroll_functional_tool_move_all(self):
logging.info('调用功能刀具出入库记录注册接口: sync_enroll_functional_tool_move_all()') # logging.info('调用功能刀具出入库记录注册接口: sync_enroll_functional_tool_move_all()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['stock.move.line'].search([('functional_tool_name_id', '!=', False)]) # objs_all = self.env['stock.move.line'].search([('functional_tool_name_id', '!=', False)])
self.get_sync_stock_move_line(objs_all, str_url, token, headers) # self.get_sync_stock_move_line(objs_all, str_url, token, headers)
#
def get_sync_stock_move_line(self, objs_all, str_url, token, headers): # def get_sync_stock_move_line(self, objs_all, str_url, token, headers):
tool_stock_list = [] # tool_stock_list = []
try: # try:
if objs_all: # if objs_all:
for item in objs_all: # for item in objs_all:
val = { # val = {
'id': item.id, # 'id': item.id,
'name': item.functional_tool_name, # 'name': item.functional_tool_name,
'code': item.code, # 'code': item.code,
'rfid': item.rfid, # 'rfid': item.rfid,
'tool_groups_name': item.tool_groups_id.name, # 'tool_groups_name': item.tool_groups_id.name,
'reference': item.reference, # 'reference': item.reference,
'barcode': item.lot_id.name, # 'barcode': item.lot_id.name,
'functional_tool_type_code': item.functional_tool_type_id.code, # 'functional_tool_type_code': item.functional_tool_type_id.code,
'diameter': item.diameter, # 'diameter': item.diameter,
'knife_tip_r_angle': item.knife_tip_r_angle, # 'knife_tip_r_angle': item.knife_tip_r_angle,
'install_tool_time': item.install_tool_time.strftime('%Y-%m-%d %H:%M:%S'), # 'install_tool_time': item.install_tool_time.strftime('%Y-%m-%d %H:%M:%S'),
'location_id': item.location_id.name, # 'location_id': item.location_id.name,
'location_dest_name': item.location_dest_id.name, # 'location_dest_name': item.location_dest_id.name,
'date': item.date.strftime('%Y-%m-%d %H:%M:%S'), # 'date': item.date.strftime('%Y-%m-%d %H:%M:%S'),
'qty_done': item.qty_done, # 'qty_done': item.qty_done,
} # }
tool_stock_list.append(val) # tool_stock_list.append(val)
kw = json.dumps(tool_stock_list, ensure_ascii=False) # kw = json.dumps(tool_stock_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) # r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() # ret = r.json()
if ret.get('code') == 200: # if ret.get('code') == 200:
return "功能刀具出入库记录注册成功" # return "功能刀具出入库记录注册成功"
else: # else:
logging.info('没有注册功能刀具出入库记录信息') # logging.info('没有注册功能刀具出入库记录信息')
except Exception as e: # except Exception as e:
logging.info("捕获错误信息:%s" % e) # logging.info("捕获错误信息:%s" % e)
#
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(StockMoveLine, self).create(vals_list) # records = super(StockMoveLine, self).create(vals_list)
for record in records: # for record in records:
if record.functional_tool_name_id: # if record.functional_tool_name_id:
record.enroll_functional_tool_move() # record.enroll_functional_tool_move()
return records # return records
#
#
class RealTimeDistributionFunctionalTools(models.Model): # class RealTimeDistributionFunctionalTools(models.Model):
_inherit = 'sf.real.time.distribution.of.functional.tools' # _inherit = 'sf.real.time.distribution.of.functional.tools'
_description = '功能刀具安全库存注册' # _description = '功能刀具安全库存注册'
#
crea_url = "/api/functional_tool_distribution/create" # crea_url = "/api/functional_tool_distribution/create"
#
# 注册同步功能刀具预警 # # 注册同步功能刀具预警
def enroll_functional_tool_real_time_distribution(self): # def enroll_functional_tool_real_time_distribution(self):
logging.info('调用功能刀具安全库存注册接口: enroll_functional_tool_real_time_distribution()') # logging.info('调用功能刀具安全库存注册接口: enroll_functional_tool_real_time_distribution()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['sf.real.time.distribution.of.functional.tools'].search([('id', '=', self.id)]) # objs_all = self.env['sf.real.time.distribution.of.functional.tools'].search([('id', '=', self.id)])
self.get_sync_real_time_distribution_functional_tools(objs_all, str_url, token, headers) # self.get_sync_real_time_distribution_functional_tools(objs_all, str_url, token, headers)
#
def sync_enroll_functional_tool_real_time_distribution_all(self): # def sync_enroll_functional_tool_real_time_distribution_all(self):
logging.info('调用功能刀具安全库存注册接口: sync_enroll_functional_tool_real_time_distribution_all()') # logging.info('调用功能刀具安全库存注册接口: sync_enroll_functional_tool_real_time_distribution_all()')
sf_sync_config = self.env['res.config.settings'].get_values() # sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token'] # token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url # str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.env['sf.real.time.distribution.of.functional.tools'].search([]) # objs_all = self.env['sf.real.time.distribution.of.functional.tools'].search([])
self.get_sync_real_time_distribution_functional_tools(objs_all, str_url, token, headers) # self.get_sync_real_time_distribution_functional_tools(objs_all, str_url, token, headers)
#
def get_sync_real_time_distribution_functional_tools(self, objs_all, str_url, token, headers): # def get_sync_real_time_distribution_functional_tools(self, objs_all, str_url, token, headers):
tool_distribution_list = [] # tool_distribution_list = []
try: # try:
if objs_all: # if objs_all:
for item in objs_all: # for item in objs_all:
functional_tool_codes = [] # functional_tool_codes = []
for obj in item.sf_functional_tool_entity_ids: # for obj in item.sf_functional_tool_entity_ids:
functional_tool_codes.append(obj.code) # functional_tool_codes.append(obj.code)
val = { # val = {
'id': item.id, # 'id': item.id,
'name': item.name, # 'name': item.name,
'tool_groups_name': item.tool_groups_id.name, # 'tool_groups_name': item.tool_groups_id.name,
'cutting_tool_type_code': item.sf_cutting_tool_type_id.code, # 'cutting_tool_type_code': item.sf_cutting_tool_type_id.code,
'diameter': item.diameter, # 'diameter': item.diameter,
'knife_tip_r_angle': item.knife_tip_r_angle, # 'knife_tip_r_angle': item.knife_tip_r_angle,
'tool_stock_num': item.tool_stock_num, # 'tool_stock_num': item.tool_stock_num,
'side_shelf_num': item.side_shelf_num, # 'side_shelf_num': item.side_shelf_num,
'on_tool_stock_num': item.on_tool_stock_num, # 'on_tool_stock_num': item.on_tool_stock_num,
'tool_stock_total': item.tool_stock_total, # 'tool_stock_total': item.tool_stock_total,
'min_stock_num': item.min_stock_num, # 'min_stock_num': item.min_stock_num,
'max_stock_num': item.max_stock_num, # 'max_stock_num': item.max_stock_num,
'batch_replenishment_num': item.batch_replenishment_num, # 'batch_replenishment_num': item.batch_replenishment_num,
'unit': item.unit, # 'unit': item.unit,
'image': '' if not item.image else base64.b64encode(item.image).decode('utf-8'), # 'image': '' if not item.image else base64.b64encode(item.image).decode('utf-8'),
'functional_tool_codes': str(functional_tool_codes), # 'functional_tool_codes': str(functional_tool_codes),
'coarse_middle_thin': item.coarse_middle_thin, # 'coarse_middle_thin': item.coarse_middle_thin,
'whether_standard_knife': item.whether_standard_knife, # 'whether_standard_knife': item.whether_standard_knife,
'suitable_machining_method_names': get_suitable_machining_method_names(item), # 'suitable_machining_method_names': get_suitable_machining_method_names(item),
'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name, # 'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name,
'handle_type_name': item.handle_type_id.name, # 'handle_type_name': item.handle_type_id.name,
'cutting_direction_names': get_cutting_direction_names(item), # 'cutting_direction_names': get_cutting_direction_names(item),
'suitable_coolant_names': get_suitable_coolant_names(item), # 'suitable_coolant_names': get_suitable_coolant_names(item),
'active': item.active # 'active': item.active
} # }
tool_distribution_list.append(val) # tool_distribution_list.append(val)
kw = json.dumps(tool_distribution_list, ensure_ascii=False) # kw = json.dumps(tool_distribution_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers) # r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json() # ret = r.json()
if ret.get('code') == 200: # if ret.get('code') == 200:
return "功能刀具出入库记录注册成功" # return "功能刀具出入库记录注册成功"
else: # else:
logging.info('没有注册功能刀具出入库记录信息') # logging.info('没有注册功能刀具出入库记录信息')
except Exception as e: # except Exception as e:
logging.info("捕获错误信息:%s" % e) # logging.info("捕获错误信息:%s" % e)
#
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(RealTimeDistributionFunctionalTools, self).create(vals_list) # records = super(RealTimeDistributionFunctionalTools, self).create(vals_list)
for record in records: # for record in records:
if record: # if record:
record.enroll_functional_tool_real_time_distribution() # record.enroll_functional_tool_real_time_distribution()
return records # return records
#
def write(self, vals): # def write(self, vals):
res = super().write(vals) # res = super().write(vals)
if vals.get('sf_functional_tool_entity_ids') or vals.get('min_stock_num') or vals.get('max_stock_num'): # if vals.get('sf_functional_tool_entity_ids') or vals.get('min_stock_num') or vals.get('max_stock_num'):
self.enroll_functional_tool_real_time_distribution() # self.enroll_functional_tool_real_time_distribution()
return res # return res

View File

@@ -128,12 +128,12 @@ class StockLot(models.Model):
record.tool_material_status = '报废' record.tool_material_status = '报废'
else: else:
record.tool_material_status = '未入库' record.tool_material_status = '未入库'
if record.tool_material_search_id: # if record.tool_material_search_id:
# 注册刀具物料状态到cloud平台 # # 注册刀具物料状态到cloud平台
record.enroll_tool_material_stock() # record.enroll_tool_material_stock()
elif record.fixture_material_search_id: # elif record.fixture_material_search_id:
# 注册夹具物料状态到cloud平台 # # 注册夹具物料状态到cloud平台
record.enroll_fixture_material_stock() # record.enroll_fixture_material_stock()
@api.model @api.model
def name_search(self, name='', args=None, operator='ilike', limit=100): def name_search(self, name='', args=None, operator='ilike', limit=100):

View File

@@ -46,7 +46,7 @@ class ToolMaterial(models.Model):
record.scrap_num = scrap_num record.scrap_num = scrap_num
record.number = usable_num + have_been_used_num + scrap_num record.number = usable_num + have_been_used_num + scrap_num
# 更新数据到cloud的动态数据 # 更新数据到cloud的动态数据
record.enroll_tool_material() # record.enroll_tool_material()
@api.model @api.model
def _read_group_cutting_tool_material_id(self, categories, domain, order): def _read_group_cutting_tool_material_id(self, categories, domain, order):

View File

@@ -46,8 +46,8 @@
</header> </header>
<sheet> <sheet>
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button name="button_safe_inventory_id" string="更新功能刀具关联的安全库存记录" <!-- <button name="button_safe_inventory_id" string="更新功能刀具关联的安全库存记录"-->
type="object" class="btn-primary"/> <!-- type="object" class="btn-primary"/>-->
<button class="oe_stat_button" groups="sf_base.group_sf_mrp_user" <button class="oe_stat_button" groups="sf_base.group_sf_mrp_user"
name="open_functional_tool_warning" name="open_functional_tool_warning"
icon="fa-list-ul" icon="fa-list-ul"

View File

@@ -831,10 +831,8 @@ class ProductProduct(models.Model):
new_time = datetime.strptime(str(fields.Date.today()), "%Y-%m-%d").strftime("%Y%m%d") new_time = datetime.strptime(str(fields.Date.today()), "%Y-%m-%d").strftime("%Y%m%d")
code += str(new_time) + '-' code += str(new_time) + '-'
stock_lot_id = self.env['stock.lot'].sudo().search( stock_lot_id = self.env['stock.lot'].sudo().search(
[('name', 'like', new_time), ('product_id.name', '=', '功能刀具')], [('name', 'like', new_time), ('product_id.categ_type', '=', '功能刀具'),
limit=1, ('product_id.tracking', '=', 'serial')], limit=1, order="id desc")
order="id desc"
)
if not stock_lot_id: if not stock_lot_id:
num = "%03d" % 1 num = "%03d" % 1
else: else:
@@ -921,13 +919,13 @@ class StockLot(models.Model):
return stock_move_id, stock_move_line_id return stock_move_id, stock_move_line_id
class StockQuant(models.Model): # class StockQuant(models.Model):
_inherit = 'stock.quant' # _inherit = 'stock.quant'
#
@api.model_create_multi # @api.model_create_multi
def create(self, vals_list): # def create(self, vals_list):
records = super(StockQuant, self).create(vals_list) # records = super(StockQuant, self).create(vals_list)
for record in records: # for record in records:
if record.lot_id.product_id.categ_id.name == '刀具': # if record.lot_id.product_id.categ_id.name == '刀具':
record.lot_id.enroll_tool_material_stock() # record.lot_id.enroll_tool_material_stock()
return records # return records