From e0a0b3d411a4ca4db5f3511477d85dec86b34c19 Mon Sep 17 00:00:00 2001 From: gqh Date: Mon, 12 Dec 2022 14:46:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96odoo16=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=B1=95=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/__manifest__.py | 2 +- sf_bf_connect/__manifest__.py | 4 +- sf_bf_connect/controllers/controllers.py | 6 +- sf_bf_connect/models/http.py | 5 +- sf_dlm/__manifest__.py | 4 +- sf_dlm/data/product_data.xml | 2 +- sf_dlm/models/product_template.py | 40 +-- sf_dlm/views/product_template_view.xml | 8 +- sf_manufacturing/__manifest__.py | 2 +- sf_manufacturing/models/mrp_production.py | 4 +- sf_manufacturing/models/mrp_workorder.py | 29 +- sf_manufacturing/models/stock.py | 6 +- sf_manufacturing/views/mrp_workorder_view.xml | 279 +++++++++--------- sf_mrs_connect/__manifest__.py | 2 +- sf_mrs_connect/controllers/controllers.py | 22 +- sf_sale/__manifest__.py | 4 +- sf_sale/models/sale_order.py | 5 +- 17 files changed, 228 insertions(+), 196 deletions(-) diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py index f4a17f1a..11931f4c 100644 --- a/sf_base/__manifest__.py +++ b/sf_base/__manifest__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. { - 'name': '机企猫智能工厂 基础模块', + 'name': '机企猫智能工厂 基础配置', 'version': '1.0', 'summary': '智能工厂基础模块', 'sequence': 1, diff --git a/sf_bf_connect/__manifest__.py b/sf_bf_connect/__manifest__.py index 1c89889d..eb0e1dfe 100644 --- a/sf_bf_connect/__manifest__.py +++ b/sf_bf_connect/__manifest__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. { - 'name': '机企猫智能工厂 连接业务平台模块', + 'name': '机企猫智能工厂 对接业务平台', 'version': '1.0', 'summary': '连接业务平台模块', 'sequence': 1, @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.cs.jikimo.com', - 'depends': ['sf_base'], + 'depends': ['sf_base', 'sf_sale', 'sf_dlm'], 'data': [ ], diff --git a/sf_bf_connect/controllers/controllers.py b/sf_bf_connect/controllers/controllers.py index aecdff23..c47fd2b8 100644 --- a/sf_bf_connect/controllers/controllers.py +++ b/sf_bf_connect/controllers/controllers.py @@ -8,7 +8,7 @@ from odoo.http import request class Sf_Bf_Connect(http.Controller): - @http.route('/api/bfm_process_order/list', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/api/bfm_process_order/list', type='json', auth='none', methods=['GET', 'POST'], csrf=False, cors="*") def get_bfm_process_order_list(self, **kw): """ @@ -24,7 +24,9 @@ class Sf_Bf_Connect(http.Controller): ret = json.loads(ret['result']) product_id = request.env.ref('sf_dlm.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) + order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create( + company_id, ret['delivery_name'], ret['delivery_telephone'], ret['delivery_address'], + ret['delivery_end_date']) i = 1 for item in ret['bfm_process_order_list']: product = request.env['product.template'].sudo().product_create(product_id, item, order_id, diff --git a/sf_bf_connect/models/http.py b/sf_bf_connect/models/http.py index 2396571f..7fee2b9a 100644 --- a/sf_bf_connect/models/http.py +++ b/sf_bf_connect/models/http.py @@ -4,12 +4,14 @@ import datetime import time import hashlib from odoo import fields, models, api -from odoo.http import request, AuthenticationError +from odoo.http import request __author__ = 'jinling.yang' _logger = logging.getLogger(__name__) +class AuthenticationError(Exception): + pass class Http(models.AbstractModel): _inherit = 'ir.http' @@ -23,6 +25,7 @@ class Http(models.AbstractModel): # 查询密钥 factory_secret = request.env['res.partner'].sudo().search( [('sf_token', '=', datas['HTTP_TOKEN'])], limit=1) + logging.info('factory_secret:%s' % factory_secret) if not factory_secret: raise AuthenticationError('无效的token') timestamp_str = int(time.time()) diff --git a/sf_dlm/__manifest__.py b/sf_dlm/__manifest__.py index 1cd1e995..da6dba4b 100644 --- a/sf_dlm/__manifest__.py +++ b/sf_dlm/__manifest__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. { - 'name': '机企猫智能工厂 产品模块', + 'name': '机企猫智能工厂 产品管理', 'version': '1.0', 'summary': '智能工厂产品模块', 'sequence': 1, @@ -12,7 +12,7 @@ 'website': 'https://www.sf.jikimo.com', 'depends': ['mrp', 'base', 'sf_manufacturing'], 'data': [ - # 'data/product_data.xml', + 'data/product_data.xml', 'views/product_template_view.xml' ], 'demo': [ diff --git a/sf_dlm/data/product_data.xml b/sf_dlm/data/product_data.xml index 2b7bedd5..c3db48ff 100644 --- a/sf_dlm/data/product_data.xml +++ b/sf_dlm/data/product_data.xml @@ -3,7 +3,7 @@ CNC加工产品模板 - + delivery product false diff --git a/sf_dlm/models/product_template.py b/sf_dlm/models/product_template.py index b626eb69..725ab8e9 100644 --- a/sf_dlm/models/product_template.py +++ b/sf_dlm/models/product_template.py @@ -1,5 +1,6 @@ from odoo import models, fields, api from odoo.exceptions import ValidationError +import logging class ResProductTemplate(models.Model): @@ -9,7 +10,7 @@ class ResProductTemplate(models.Model): model_long = fields.Float('模型长[mm]', digits=(16, 3)) model_width = fields.Float('模型宽[mm]', digits=(16, 3)) model_height = fields.Float('模型高[mm]', digits=(16, 3)) - model_volume = fields.Float('模型体积[mm]', compute='_compute_model_volume', store=True) + model_volume = fields.Float('模型体积[m³]') model_machining_precision = fields.Selection([ ('±0.10mm', '±0.10mm'), ('±0.05mm', '±0.05mm'), @@ -22,35 +23,38 @@ class ResProductTemplate(models.Model): model_process_parameters_id = fields.Many2one('sf.processing.technology', string='工艺参数') model_price = fields.Float('模型单价', digits=(16, 3)) model_remark = fields.Char('模型备注说明') - long = fields.Float('长[mm]', digits=(16, 3)) + length = fields.Float('长[mm]', digits=(16, 3)) width = fields.Float('宽[mm]', digits=(16, 3)) height = fields.Float('高[mm]', digits=(16, 3)) materials_id = fields.Many2one('sf.production.materials', string='材料') materials_type_id = fields.Many2one('sf.materials.model', string='材料型号') - volume = fields.Float(compute='_compute_volume', store=True) + # volume = fields.Float(compute='_compute_volume', store=True) single_manufacturing = fields.Boolean(string="单个制造") - @api.depends('long', 'width', 'height') - def _compute_volume(self): - self.volume = self.long * self.width * self.height + # @api.depends('long', 'width', 'height') + # def _compute_volume(self): + # self.volume = self.long * self.width * self.height - @api.depends('model_long', 'model_width', 'model_height') - def _compute_model_volume(self): - self.model_volume = self.model_long * self.model_width * self.model_height + # @api.depends('model_long', 'model_width', 'model_height') + # def _compute_model_volume(self): + # self.model_volume = self.model_long * self.model_width * self.model_height # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品 def product_create(self, product_id, item, order_id, order_number, i): copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy() copy_product_id.product_tmpl_id.active = True + logging.info('product_create:%s' % item) vals = { 'name': '%s-%s' % (order_id.name, i), 'model_long': item['model_long'], 'model_width': item['model_width'], 'model_height': item['model_height'], - 'model_volume': item['model_volume'], + 'length': item['long'], + 'width': item['width'], + 'height': item['height'], + 'volume': item['long'] * item['width'] * item['height'], 'model_price': item['price'], - 'model_total_amount': item['total_amount'], - 'model_number': item['number'], + 'single_manufacturing': True, 'list_price': item['price'], 'materials_id': self.env['sf.production.materials'].search( [('materials_no', '=', item['texture_code'])]).id, @@ -65,6 +69,7 @@ class ResProductTemplate(models.Model): 'barcode': item['barcode'], 'active': True } + logging.info('product_create1:%s' % item) copy_product_id.sudo().write(vals) return copy_product_id @@ -109,21 +114,16 @@ class ResMrpBom(models.Model): # 三、胚料的长宽高均要大于模型的长宽高; # 四、如果匹配成功多个胚料,则选取体积最小的胚料; def bom_create_Line(self, product): + logging.info('bom_create_Line:%s' % product) embryo = self.env['product.product'].search( [('categ_id.is_embryo', '=', True), ('materials_type_id', '=', product.materials_type_id.id), - ('long', '>', product.long), ('width', '>', product.width), + ('length', '>', product.length), ('width', '>', product.width), ('height', '>', product.height) ], limit=1, order='volume desc' ) - vals = { - 'bom_id': self.id, - 'product_id': embryo.id, - 'product_tmpl_id': embryo.product_tmpl_id.id, - 'product_qty': 1, - 'product_uom_id': 1 - } + logging.info('bom_create_Line1:%s' % product) return self.env['mrp.bom.line'].create(vals) diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index d8975017..76cbdb32 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -13,12 +13,12 @@ -