Merge branch refs/heads/develop into refs/heads/hotfix/刀具预调仪

This commit is contained in:
杨金灵
2024-06-06 09:30:50 +08:00
13 changed files with 356 additions and 155 deletions

View File

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

View File

@@ -1,6 +1,7 @@
import json
import base64
import requests
import logging
from odoo import models, api
from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import UserError
@@ -10,30 +11,36 @@ class StockLot(models.Model):
_inherit = 'stock.lot'
_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()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
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 = []
if objs_all:
for item in objs_all:
val = {
'name': item.name,
'tool_material_status': item.tool_material_status,
'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)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
return '夹具物料序列号注册成功'
else:
raise UserError("没有注册夹具物料序列号信息")
try:
if objs_all:
for item in objs_all:
val = {
'name': item.name,
'tool_material_status': item.tool_material_status,
'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)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
logging.info("夹具物料序列号每日同步成功")
return '夹具物料序列号注册成功'
else:
logging.info("没有注册夹具物料序列号信息")
except Exception as e:
logging.info("夹具物料序列号同步失败:%s" % e)
class FixtureMaterialSearch(models.Model):
@@ -42,41 +49,46 @@ class FixtureMaterialSearch(models.Model):
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()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.search([('id', '=', self.id)])
objs_all = self.search([])
fixture_material_list = []
if objs_all:
for obj in objs_all:
val = {
'name': obj.name,
'id': obj.id,
'fixture_material_code': obj.fixture_material_id.code,
'fixture_model_code': obj.fixture_model_id.code,
'specification_name': obj.specification_fixture_id.name,
'image': '' if not obj.image else base64.b64encode(obj.image).decode('utf-8'),
'number': obj.number,
'usable_num': obj.usable_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)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
return '夹具物料注册成功'
else:
raise UserError("没有注册夹具物料信息")
try:
if objs_all:
for obj in objs_all:
val = {
'name': obj.name,
'id': obj.id,
'fixture_material_code': obj.fixture_material_id.code,
'fixture_model_code': obj.fixture_model_id.code,
'specification_name': obj.specification_fixture_id.name,
'image': '' if not obj.image else base64.b64encode(obj.image).decode('utf-8'),
'number': obj.number,
'usable_num': obj.usable_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)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
logging.info("夹具物料每日同步成功")
return '夹具物料注册成功'
else:
logging.info("没有注册夹具物料信息")
except Exception as e:
logging.info("夹具物料同步失败:%s" % e)
@api.model_create_multi
def create(self, vals_list):
records = super(FixtureMaterialSearch, self).create(vals_list)
for record in records:
if record:
record.enroll_fixture_material()
return records
# @api.model_create_multi
# def create(self, vals_list):
# records = super(FixtureMaterialSearch, self).create(vals_list)
# for record in records:
# if record:
# record.enroll_fixture_material()
# return records

View File

@@ -33,23 +33,26 @@ def get_suitable_coolant_names(item):
class ToolDatasync(models.Model):
_name = 'sf.tool.datasync'
_description = '定时同步所有刀具'
_description = '定时同步所有刀具、夹具'
def _cron_tool_datasync_all(self):
try:
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()
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()
logging.info("功能刀具列表每日同步成功")
self.env['sf.functional.tool.warning'].sudo().sync_enroll_functional_tool_warning_all()
logging.info("功能刀具预警每日同步成功")
self.env['stock.move.line'].sudo().sync_enroll_functional_tool_move_all()
logging.info("功能刀具出入库记录每日同步成功")
self.env[
'sf.real.time.distribution.of.functional.tools'].sudo().sync_enroll_functional_tool_real_time_distribution_all()
logging.info("功能刀具安全库存每日同步成功")
logging.info("已全部同步完成!!!")
# self.env['sf.functional.tool.warning'].sudo().sync_enroll_functional_tool_warning_all()
# logging.info("功能刀具预警每日同步成功")
# self.env['stock.move.line'].sudo().sync_enroll_functional_tool_move_all()
# logging.info("功能刀具出入库记录每日同步成功")
# self.env['sf.real.time.distribution.of.functional.tools'].sudo().sync_enroll_functional_tool_real_time_distribution_all()
# logging.info("功能刀具安全库存每日同步成功")
except Exception as e:
logging.info("捕获错误信息:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员")
@@ -59,24 +62,25 @@ class StockLot(models.Model):
_inherit = 'stock.lot'
_description = '刀具物料序列号注册'
def enroll_tool_material_stock(self):
logging.info('调用刀具物料序列号注册接口: enroll_tool_material_stock()')
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
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])])
self._get_sync_stock_lot(objs_all, str_url, token, headers)
# def enroll_tool_material_stock(self):
# logging.info('调用刀具物料序列号注册接口: enroll_tool_material_stock()')
# sf_sync_config = self.env['res.config.settings'].get_values()
# token = sf_sync_config['token']
# sf_secret_key = sf_sync_config['sf_secret_key']
# headers = Common.get_headers(self, token, sf_secret_key)
# 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])])
# self._get_sync_stock_lot(objs_all, str_url, token, headers)
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()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
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)
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)
ret = r.json()
if ret.get('code') == 200:
return '刀具物料序列号注册成功'
logging.info("刀具物料序列号每日同步成功")
return '刀具(夹具)物料序列号注册成功'
else:
logging.info("没有注册刀具物料序列号信息")
logging.info("没有刀具物料序列号信息")
except Exception as e:
logging.info("捕获错误信息:%s" % e)
logging.info("刀具物料序列号同步失败:%s" % e)
class ToolMaterial(models.Model):
@@ -108,18 +113,18 @@ class ToolMaterial(models.Model):
crea_url = '/api/tool_material/create'
def enroll_tool_material(self):
logging.info('调用刀具物料注册接口: enroll_tool_material()')
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url
objs_all = self.search([('id', '=', self.id)])
self._get_sync_tool_material_search(objs_all, str_url, token, headers)
# def enroll_tool_material(self):
# logging.info('调用刀具物料注册接口: enroll_tool_material()')
# sf_sync_config = self.env['res.config.settings'].get_values()
# token = sf_sync_config['token']
# sf_secret_key = sf_sync_config['sf_secret_key']
# headers = Common.get_headers(self, token, sf_secret_key)
# str_url = sf_sync_config['sf_url'] + self.crea_url
# objs_all = self.search([('id', '=', self.id)])
# self._get_sync_tool_material_search(objs_all, str_url, token, headers)
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()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
@@ -150,11 +155,14 @@ class ToolMaterial(models.Model):
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
logging.info("刀具物料每日同步成功")
return '刀具物料注册成功'
else:
logging.info('没有注册刀具物料信息')
except Exception as e:
logging.info("捕获错误信息:%s" % e)
logging.info("刀具物料同步失败:%s" % e)
class FunctionalCuttingToolEntity(models.Model):
@@ -164,18 +172,18 @@ class FunctionalCuttingToolEntity(models.Model):
crea_url = "/api/functional_tool_entity/create"
# 注册同步功能刀具列表
def enroll_functional_tool_entity(self):
logging.info('调用功能刀具列表注册接口: enroll_functional_tool_entity()')
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
str_url = sf_sync_config['sf_url'] + self.crea_url
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)
# def enroll_functional_tool_entity(self):
# logging.info('调用功能刀具列表注册接口: enroll_functional_tool_entity()')
# sf_sync_config = self.env['res.config.settings'].get_values()
# token = sf_sync_config['token']
# sf_secret_key = sf_sync_config['sf_secret_key']
# headers = Common.get_headers(self, token, sf_secret_key)
# str_url = sf_sync_config['sf_url'] + self.crea_url
# 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)
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()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
@@ -202,6 +210,7 @@ class FunctionalCuttingToolEntity(models.Model):
'coarse_middle_thin': item.coarse_middle_thin,
'new_former': item.new_former,
'tool_loading_length': item.tool_loading_length,
'handle_length': item.handle_length,
'functional_tool_length': item.functional_tool_length,
'effective_length': item.effective_length,
'max_lifetime_value': item.max_lifetime_value,
@@ -234,11 +243,14 @@ class FunctionalCuttingToolEntity(models.Model):
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if ret.get('code') == 200:
logging.info("功能刀具列表每日同步成功")
return "功能刀具注册成功"
else:
logging.info('没有注册功能刀具信息')
except Exception as e:
logging.info("捕获错误信息:%s" % e)
logging.info("功能刀具同步失败:%s" % e)
class FunctionalToolWarning(models.Model):

View File

@@ -46,6 +46,8 @@ class ToolMaterial(models.Model):
record.scrap_num = scrap_num
record.number = usable_num + have_been_used_num + scrap_num
@api.model
def _read_group_cutting_tool_material_id(self, categories, domain, order):
cutting_tool_material_id = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)