113 lines
5.5 KiB
Python
113 lines
5.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of SmartGo. See LICENSE file for full copyright and licensing details.
|
|
import logging
|
|
from odoo import api, fields, models
|
|
from odoo.exceptions import ValidationError
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ResConfigSettings(models.TransientModel):
|
|
_inherit = 'res.config.settings'
|
|
|
|
token = fields.Char(string='TOKEN', default='b811ac06-3f00-11ed-9aed-0242ac110003')
|
|
sf_secret_key = fields.Char(string='密钥', default='wBmxej38OkErKhD6')
|
|
sf_url = fields.Char(string='访问地址', default='https://sf.cs.jikimo.com')
|
|
ftp_host = fields.Char(string='FTP的ip')
|
|
ftp_port = fields.Char(string='FTP端口')
|
|
ftp_user = fields.Char(string='FTP用户')
|
|
ftp_password = fields.Char(string='FTP密码')
|
|
|
|
def sf_all_sync(self):
|
|
try:
|
|
self.env['sf.production.materials'].sync_all_production_materials()
|
|
_logger.info("同步资源库材料")
|
|
self.env['sf.materials.model'].sync_all_materials_model()
|
|
_logger.info("同步资源库材料型号")
|
|
self.env['sf.production.process.category'].sync_all_production_process_category()
|
|
_logger.info("同步资源库表面工艺类别")
|
|
self.env['sf.production.process'].sync_all_production_process()
|
|
_logger.info("同步资源库表面工艺")
|
|
self.env['sf.processing.technology'].sync_all_processing_technology()
|
|
_logger.info("同步资源库加工工艺")
|
|
self.env['sf.machine.brand.tags'].sync_all_machine_brand_tags()
|
|
_logger.info("同步资源库品牌类别")
|
|
self.env['sf.machine.brand'].sync_all_machine_brand()
|
|
_logger.info("同步资源库品牌")
|
|
self.env['sf.machine.control_system'].sync_all_machine_tool_type_control_system()
|
|
_logger.info("同步资源库控制系统")
|
|
|
|
self.env['sf.machine_tool.category'].sync_all_machine_tool_category()
|
|
_logger.info("同步资源库机床类型")
|
|
# self.env['sf.production.process.parameter'].sync_all_production_process_parameter()
|
|
# _logger.info("同步表面工艺参数")
|
|
_logger.info("同步所有刀具物料...")
|
|
self.env['sf.cutting.tool.material'].sync_all_cutting_tool_material()
|
|
_logger.info("同步所有刀具物料完成")
|
|
_logger.info("同步所有刀具类型...")
|
|
self.env['sf.cutting.tool.type'].sync_all_tool_type()
|
|
_logger.info("同步所有刀具类型完成")
|
|
_logger.info("定时同步所有功能刀具类型列表...")
|
|
self.env['sf.functional.cutting.tool.model'].sync_all_functional_cutting_tool_model()
|
|
_logger.info("同步所有功能刀具类型完成")
|
|
_logger.info("同步所有刀具型号...")
|
|
self.env['sf.cutting.tool.model'].sync_all_tool_model()
|
|
_logger.info("同步所有刀具型号完成")
|
|
_logger.info("同步所有功能刀具列表...")
|
|
self.env['sf.functional.cutting.tool'].sync_all_functional_cutting_tool()
|
|
_logger.info("同步所有功能刀具列表完成")
|
|
|
|
self.env['sf.fixture.material'].sync_all_fixture_material()
|
|
_logger.info("同步夹具物料")
|
|
# self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type()
|
|
# _logger.info("同步联装类型")
|
|
# self.env['sf.fixture.model'].sync_all_fixture_model()
|
|
# _logger.info("同步夹具型号")
|
|
# self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type()
|
|
# _logger.info("同步功能夹具类型")
|
|
# self.env['sf.functional.fixture'].sync_all_functional_fixture()
|
|
# _logger.info("同步功能夹具")
|
|
self.env['sf.machine_tool.type'].sync_all_machine_tool_type()
|
|
_logger.info("同步资源库机床型号")
|
|
except Exception as e:
|
|
_logger.info("捕获错误信息:%s" % e)
|
|
raise ValidationError("数据错误导致同步失败,请联系管理员")
|
|
|
|
@api.model
|
|
def get_values(self):
|
|
"""
|
|
重载获取参数的方法,参数都存在系统参数中
|
|
:return:
|
|
"""
|
|
values = super(ResConfigSettings, self).get_values()
|
|
config = self.env['ir.config_parameter'].sudo()
|
|
token = config.get_param('token', default='')
|
|
sf_secret_key = config.get_param('sf_secret_key', default='')
|
|
sf_url = config.get_param('sf_url', default='')
|
|
ftp_host = config.get_param('ftp_host', default='')
|
|
ftp_port = config.get_param('ftp_port', default='')
|
|
ftp_user = config.get_param('ftp_user', default='')
|
|
ftp_password = config.get_param('ftp_password', default='')
|
|
|
|
values.update(
|
|
token=token,
|
|
sf_secret_key=sf_secret_key,
|
|
sf_url=sf_url,
|
|
ftp_host=ftp_host,
|
|
ftp_port=ftp_port,
|
|
ftp_user=ftp_user,
|
|
ftp_password=ftp_password
|
|
)
|
|
return values
|
|
|
|
def set_values(self):
|
|
super(ResConfigSettings, self).set_values()
|
|
ir_config = self.env['ir.config_parameter'].sudo()
|
|
ir_config.set_param("token", self.token or "")
|
|
ir_config.set_param("sf_secret_key", self.sf_secret_key or "")
|
|
ir_config.set_param("sf_url", self.sf_url or "")
|
|
ir_config.set_param("ftp_host", self.ftp_host or "")
|
|
ir_config.set_param("ftp_port", self.ftp_port or "")
|
|
ir_config.set_param("ftp_user", self.ftp_user or "")
|
|
ir_config.set_param("ftp_password", self.ftp_password or "")
|