212
This commit is contained in:
@@ -1 +1,4 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from . import controllers
|
||||
from . import models
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 同步模块',
|
||||
'name': '机企猫智能工厂 连接业务平台模块',
|
||||
'version': '1.0',
|
||||
'summary': '智能工厂同步模块',
|
||||
'summary': '连接业务平台模块',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
在本模块,同步资源库
|
||||
在本模块,接收业务平台的模块
|
||||
""",
|
||||
'category': 'YZ',
|
||||
'website': 'https://www.sf.cs.jikimo.com',
|
||||
'depends': ['account', 'sf_base', 'base', 'sale'],
|
||||
'depends': ['sf_base'],
|
||||
'data': [
|
||||
# 'views/sale_process_order_view.xml'
|
||||
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from .import controllers
|
||||
|
||||
|
||||
@@ -4,29 +4,38 @@ import logging
|
||||
from datetime import date, timedelta
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
from odoo.addons.mrs_gateway_api.models.common import Common
|
||||
from odoo.addons.mrs_gateway_api.models.basicdata_str import BasicDataStr
|
||||
|
||||
|
||||
class Sf_Bf_Connect(http.Controller):
|
||||
|
||||
@http.route('/api/bfm_process_order/list', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
@http.route('/api/bfm_process_order/list', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_bfm_process_order_list(self, **kw):
|
||||
"""
|
||||
获取业务平台传送来的业务平台订单
|
||||
获取业务平台传送来的订单
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
result = json.loads('bfm_process_order_list')
|
||||
for item in result:
|
||||
self.env['mrs.production.process'].create({
|
||||
"id": item['id'],
|
||||
"model_file": item['model_file'],
|
||||
"model_name": item['model_name'],
|
||||
"type": item['type'],
|
||||
"surface_technics": item['surface_technics'],
|
||||
"unit_price": item['unit_price'],
|
||||
"amount": item['amount'],
|
||||
"money": item['money']
|
||||
})
|
||||
res = {'status': 1, 'factory_order_no': ''}
|
||||
logging.info('get_bfm_process_order_list:%s' % kw)
|
||||
try:
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
ret = json.loads(ret['result'])
|
||||
product_id = request.env.ref('sf_bpm_api.product_template_sf').sudo()
|
||||
company_id = request.env.ref('base.main_company').sudo()
|
||||
order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create(ret['delivery_end_date'], company_id)
|
||||
i = 1
|
||||
for item in ret['bfm_process_order_list']:
|
||||
product = request.env['product.template'].sudo().product_create(product_id, item, order_id,
|
||||
ret['order_number'], i)
|
||||
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
|
||||
bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(product)
|
||||
bom.with_user(request.env.ref("base.user_admin")).bom_create_Line(product)
|
||||
i += 1
|
||||
res['factory_order_no'] = order_id.name
|
||||
return json.JSONEncoder().encode(res)
|
||||
except Exception as e:
|
||||
logging.info('get_bfm_process_order_list error:%s' % e)
|
||||
res['status'] = -1
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@@ -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='业务平台订单')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- <record model="ir.ui.view" id="view_sf_form_inherit">-->
|
||||
<!-- <field name="model">sale.order</field>-->
|
||||
<!-- <field name="inherit_id" ref="sale.view_order_form"/>-->
|
||||
<!-- <field name="arch" type="xml">-->
|
||||
<!--<!– <xpath expr="//page[@name='Customer Signature']" position="before">–>-->
|
||||
<!--<!– <page string="Bfm Line">–>-->
|
||||
<!--<!– <group>–>-->
|
||||
<!--<!– <field name="bfm_process_order_ids"/>–>-->
|
||||
<!--<!– </group>–>-->
|
||||
<!--<!– </page>–>-->
|
||||
<!--<!– </xpath>–>-->
|
||||
<!-- </field>-->
|
||||
<!-- </record>-->
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user