212
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
from . import sf_process_order
|
||||
from . import http
|
||||
from . import models
|
||||
|
||||
|
||||
|
||||
40
sf_bf_connect/models/http.py
Normal file
40
sf_bf_connect/models/http.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import datetime
|
||||
import time
|
||||
import hashlib
|
||||
from odoo import fields, models, api
|
||||
from odoo.http import request, AuthenticationError
|
||||
|
||||
__author__ = 'jinling.yang'
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Http(models.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
@classmethod
|
||||
def _auth_method_sf_token(cls):
|
||||
# 从headers.environ中获取对方传过来的token,timestamp,加密的校验字符串
|
||||
datas = request.httprequest.headers.environ
|
||||
if 'HTTP_TOKEN' in datas:
|
||||
_logger.info('token:%s' % datas['HTTP_TOKEN'])
|
||||
# 查询密钥
|
||||
factory_secret = request.env['res.partner'].sudo().search(
|
||||
[('sf_token', '=', datas['HTTP_TOKEN'])], limit=1)
|
||||
if not factory_secret:
|
||||
raise AuthenticationError('无效的token')
|
||||
timestamp_str = int(time.time())
|
||||
# 设置API接口请求时间,不能超过5秒
|
||||
deltime = datetime.timedelta(seconds=60)
|
||||
if abs(int(datas['HTTP_TIMESTAMP'])-timestamp_str) > deltime.seconds:
|
||||
raise AuthenticationError('请求已过期')
|
||||
# 获得sha1_str加密字符串
|
||||
post_time = int(datas['HTTP_TIMESTAMP'])
|
||||
check_str = '%s%s%s' % (datas['HTTP_TOKEN'], post_time, factory_secret.sf_secret_key)
|
||||
check_sf_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
||||
if check_sf_str != datas['HTTP_CHECKSTR']:
|
||||
raise AuthenticationError('数据校验不通过')
|
||||
else:
|
||||
raise AuthenticationError('请求参数中无token')
|
||||
28
sf_bf_connect/models/models.py
Normal file
28
sf_bf_connect/models/models.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import uuid
|
||||
import string
|
||||
import random
|
||||
|
||||
|
||||
from odoo import fields, models, api
|
||||
|
||||
__author__ = 'jinling.yang'
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
# 获取token,token自动生成且唯一
|
||||
def get_token(self):
|
||||
return uuid.uuid1()
|
||||
|
||||
# 获取密钥(大小字母+数字随机)
|
||||
def get_secret(self):
|
||||
ran_str = ''.join(random.sample(string.ascii_letters + string.digits, 16))
|
||||
return ran_str
|
||||
|
||||
sf_token = fields.Char(u'Token', default=get_token)
|
||||
sf_secret_key = fields.Char(u'密钥', default=get_secret)
|
||||
@@ -1,34 +0,0 @@
|
||||
from odoo import models,fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class bfmOrderLine(models.Model):
|
||||
_name = 'sf.bfm.order.line'
|
||||
_description = '业务平台订单'
|
||||
|
||||
model_file = fields.Binary('模型文件', attachment=False)
|
||||
model_name = fields.char('模型名称')
|
||||
type = fields.Many2one('mrs.materials.model', '型号')
|
||||
surface_technics = fields.Many2one('mrs.production.process', string='表面工艺')
|
||||
# technological_parameter = fields.Many2one('',string='工艺参数')
|
||||
unit_price = fields.Float('单价')
|
||||
amount = fields.Integer('数量')
|
||||
money = fields.Float('金额')
|
||||
|
||||
|
||||
class sale(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
bfm_process_order_ids = fields.Many2one('sf.bfm.order.line', string='业务平台订单')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user