1、添加定时同步刀具物料和功能刀具相关的信息到cloud的功能;2、添加同步所以刀具物料和所以功能刀具相关记录同步接口;
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
'views/menu_view.xml',
|
'views/menu_view.xml',
|
||||||
'views/tool_material_search.xml',
|
'views/tool_material_search.xml',
|
||||||
'views/fixture_material_search_views.xml',
|
'views/fixture_material_search_views.xml',
|
||||||
|
'data/tool_data.xml',
|
||||||
],
|
],
|
||||||
'demo': [
|
'demo': [
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<record model="ir.cron" id="ir_cron_sf_tool_datasync">
|
||||||
<!-- <record model="sf.machine.table.tool.changing.apply" id="sf_create_tool_change_application">-->
|
<field name="name">定时同步刀具物料、功能刀具信息到cloud</field>
|
||||||
|
<field name="model_id" ref="model_sf_tool_datasync"/>
|
||||||
<!-- </record>-->
|
<field name="state">code</field>
|
||||||
</data>
|
<field name="code">model._cron_tool_datasync_all()</field>
|
||||||
|
<field name="interval_number">1</field>
|
||||||
|
<field name="interval_type">days</field>
|
||||||
|
<field name="numbercall">-1</field>
|
||||||
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
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, ValidationError
|
||||||
|
|
||||||
|
|
||||||
def get_suitable_machining_method_names(item):
|
def get_suitable_machining_method_names(item):
|
||||||
@@ -30,6 +31,30 @@ def get_suitable_coolant_names(item):
|
|||||||
return suitable_coolant_names
|
return suitable_coolant_names
|
||||||
|
|
||||||
|
|
||||||
|
class ToolDatasync(models.Model):
|
||||||
|
_name = 'sf.tool.datasync'
|
||||||
|
_description = '定时同步所有刀具'
|
||||||
|
|
||||||
|
def _cron_tool_datasync_all(self):
|
||||||
|
try:
|
||||||
|
self.env['stock.lot'].sudo().sync_enroll_tool_material_stock_all()
|
||||||
|
logging.info("刀具物料序列号每日同步成功")
|
||||||
|
self.env['sf.tool.material.search'].sudo().sync_enroll_tool_material_all()
|
||||||
|
logging.info("刀具物料每日同步成功")
|
||||||
|
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("功能刀具安全库存每日同步成功")
|
||||||
|
except Exception as e:
|
||||||
|
logging.info("捕获错误信息:%s" % e)
|
||||||
|
raise ValidationError("数据错误导致同步失败,请联系管理员")
|
||||||
|
|
||||||
|
|
||||||
class StockLot(models.Model):
|
class StockLot(models.Model):
|
||||||
_inherit = 'stock.lot'
|
_inherit = 'stock.lot'
|
||||||
_description = '刀具物料序列号注册'
|
_description = '刀具物料序列号注册'
|
||||||
@@ -41,6 +66,18 @@ class StockLot(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def sync_enroll_tool_material_stock_all(self):
|
||||||
|
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)])
|
||||||
|
self._get_sync_stock_lot(objs_all, str_url, token, headers)
|
||||||
|
|
||||||
|
def _get_sync_stock_lot(self, objs_all, str_url, token, headers):
|
||||||
tool_material_stock_list = []
|
tool_material_stock_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
@@ -73,6 +110,18 @@ class ToolMaterial(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def sync_enroll_tool_material_all(self):
|
||||||
|
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([])
|
||||||
|
self._get_sync_tool_material_search(objs_all, str_url, token, headers)
|
||||||
|
|
||||||
|
def _get_sync_tool_material_search(self, objs_all, str_url, token, headers):
|
||||||
tool_material_list = []
|
tool_material_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
@@ -120,6 +169,18 @@ class FunctionalCuttingToolEntity(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def esync_enroll_functional_tool_entity_all(self):
|
||||||
|
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([])
|
||||||
|
self._get_sync_functional_cutting_tool_entity(objs_all, str_url, token, headers)
|
||||||
|
|
||||||
|
def _get_sync_functional_cutting_tool_entity(self, objs_all, str_url, token, headers):
|
||||||
functional_tool_list = []
|
functional_tool_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
@@ -201,6 +262,18 @@ class FunctionalToolWarning(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def sync_enroll_functional_tool_warning_all(self):
|
||||||
|
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.tool.warning'].search([])
|
||||||
|
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):
|
||||||
tool_warning_list = []
|
tool_warning_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
@@ -262,6 +335,18 @@ class StockMoveLine(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def sync_enroll_functional_tool_move_all(self):
|
||||||
|
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['stock.move.line'].search([('functional_tool_name_id', '!=', False)])
|
||||||
|
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):
|
||||||
tool_stock_list = []
|
tool_stock_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
@@ -314,6 +399,18 @@ class RealTimeDistributionFunctionalTools(models.Model):
|
|||||||
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)
|
||||||
|
|
||||||
|
def sync_enroll_functional_tool_real_time_distribution_all(self):
|
||||||
|
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.real.time.distribution.of.functional.tools'].search([])
|
||||||
|
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):
|
||||||
tool_distribution_list = []
|
tool_distribution_list = []
|
||||||
if objs_all:
|
if objs_all:
|
||||||
for item in objs_all:
|
for item in objs_all:
|
||||||
|
|||||||
Reference in New Issue
Block a user