diff --git a/sf_base/security/group_security.xml b/sf_base/security/group_security.xml index c32538c7..87243b79 100644 --- a/sf_base/security/group_security.xml +++ b/sf_base/security/group_security.xml @@ -1,13 +1,27 @@ - - 员工 + + + 合作伙伴 1 - - 管理 - 2 + + 加工工厂 + + + + + + 供应商 + + + + + + 编程中心 + + diff --git a/sf_bf_connect/controllers/controllers.py b/sf_bf_connect/controllers/controllers.py index 4670470a..07854e2b 100644 --- a/sf_bf_connect/controllers/controllers.py +++ b/sf_bf_connect/controllers/controllers.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import json import logging -from datetime import date, timedelta from odoo import http from odoo.http import request @@ -19,27 +18,18 @@ class Sf_Bf_Connect(http.Controller): 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_dlm.product_template_sf').sudo() self_machining_id = request.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo() outsource_id = request.env.ref('sf_dlm.product_embryo_sf_outsource').sudo() purchase_id = request.env.ref('sf_dlm.product_embryo_sf_purchase').sudo() company_id = request.env.ref('base.main_company').sudo() - user_id = request.env.ref('base.user_admin').sudo() + # user_id = request.env.ref('base.user_admin').sudo() bfm_process_order_list = json.loads(kw['bfm_process_order_list']) order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create( company_id, kw['delivery_name'], kw['delivery_telephone'], kw['delivery_address'], - kw['delivery_end_date'], user_id) + kw['delivery_end_date']) i = 1 for item in bfm_process_order_list: - # product_has = request.env['product.template'].with_user(request.env.ref("base.user_admin")).search([('barcode','=', item['barcode'])]) - # if product_has: - # logging.info('product_has:%s' % product_has) - # logging.info('barcode:%s' % item['barcode']) - # order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product_has, item) - # else: product = request.env['product.template'].sudo().product_create(product_id, item, order_id, kw['order_number'], i) bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product) @@ -61,8 +51,14 @@ class Sf_Bf_Connect(http.Controller): request.env.ref("base.user_admin")).bom_create( self_machining_embryo, 'normal', False) # 创建胚料里bom的组件 - self_machining_bom.with_user(request.env.ref("base.user_admin")).bom_create_line( + self_machining_bom_line = self_machining_bom.with_user( + request.env.ref("base.user_admin")).bom_create_line( self_machining_embryo) + if self_machining_bom_line == False: + res['status'] = 2 + res['message'] = '该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配' + request.cr.rollback() + return json.JSONEncoder().encode(res) # 产品配置bom product_bom_self_machining = request.env['mrp.bom'].with_user( request.env.ref("base.user_admin")).bom_create( @@ -81,7 +77,13 @@ class Sf_Bf_Connect(http.Controller): outsource_embryo, 'subcontract', True) # 创建胚料的bom的组件 - outsource_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(outsource_embryo) + outsource_bom_line = outsource_bom.with_user( + request.env.ref("base.user_admin")).bom_create_line(outsource_embryo) + if outsource_bom_line == False: + res['status'] = 2 + res['message'] = '该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配' + request.cr.rollback() + return json.JSONEncoder().encode(res) # 产品配置bom product_bom_outsource = request.env['mrp.bom'].with_user( request.env.ref("base.user_admin")).bom_create(product, 'normal', False) @@ -100,8 +102,9 @@ class Sf_Bf_Connect(http.Controller): order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) 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 res['message'] = '工厂创建销售订单和产品失败,请联系管理员' - return json.JSONEncoder().encode(res) + return json.JSONEncoder().encode(res) diff --git a/sf_bf_connect/models/http.py b/sf_bf_connect/models/http.py index 23c66406..eb969eb6 100644 --- a/sf_bf_connect/models/http.py +++ b/sf_bf_connect/models/http.py @@ -3,7 +3,7 @@ import logging import datetime import time import hashlib -from odoo import fields, models, api +from odoo import models from odoo.http import request __author__ = 'jinling.yang' diff --git a/sf_bf_connect/models/models.py b/sf_bf_connect/models/models.py index 3eeac229..5aba960a 100644 --- a/sf_bf_connect/models/models.py +++ b/sf_bf_connect/models/models.py @@ -5,7 +5,7 @@ import string import random -from odoo import fields, models, api +from odoo import fields, models __author__ = 'jinling.yang' diff --git a/sf_dlm/models/product_supplierinfo.py b/sf_dlm/models/product_supplierinfo.py index ae850401..25dd7398 100644 --- a/sf_dlm/models/product_supplierinfo.py +++ b/sf_dlm/models/product_supplierinfo.py @@ -1,4 +1,4 @@ -from odoo import models, fields, api +from odoo import models class ResSupplierInfo(models.Model): @@ -7,5 +7,6 @@ class ResSupplierInfo(models.Model): def _compute_is_subcontractor(self): for supplier in self: boms = supplier.product_id.variant_bom_ids - boms |= supplier.product_tmpl_id.bom_ids.filtered(lambda b: not b.product_id or b.product_id in (supplier.product_id or supplier.product_tmpl_id.product_variant_ids)) - supplier.is_subcontractor = supplier.partner_id in boms.subcontractor_id \ No newline at end of file + boms |= supplier.product_tmpl_id.bom_ids.filtered(lambda b: not b.product_id or b.product_id in ( + supplier.product_id or supplier.product_tmpl_id.product_variant_ids)) + supplier.is_subcontractor = supplier.partner_id in boms.subcontractor_id diff --git a/sf_dlm/models/product_template.py b/sf_dlm/models/product_template.py index 8d271396..115f42d4 100644 --- a/sf_dlm/models/product_template.py +++ b/sf_dlm/models/product_template.py @@ -1,10 +1,6 @@ -from odoo import models, fields, api -from odoo.exceptions import ValidationError +from odoo import models, fields import logging import base64 -import os -# from OCC.Extend.DataExchange import read_step_file, write_stl_file -from odoo.modules import get_resource_path class ResProductTemplate(models.Model): @@ -12,6 +8,8 @@ class ResProductTemplate(models.Model): # 模型的长,宽,高,体积,精度,材料 model_name = fields.Char('模型名称') + categ_type = fields.Selection( + [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料")], string='产品的类别', related='categ_id.type', store=True) model_long = fields.Float('模型长[mm]', digits=(16, 3)) model_width = fields.Float('模型宽[mm]', digits=(16, 3)) model_height = fields.Float('模型高[mm]', digits=(16, 3)) @@ -223,7 +221,7 @@ class ResMrpBom(models.Model): 'product_qty': 1, 'product_uom_id': 1 }) - if bom_type == 'subcontract' and product_type != False: + if bom_type == 'subcontract' and product_type is not False: subcontract = self.get_supplier(product.materials_type_id) bom_id.subcontractor_id = subcontract.partner_id.id return bom_id @@ -233,15 +231,18 @@ class ResMrpBom(models.Model): # 胚料所需原材料公式:当前的胚料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤) def bom_create_line(self, embryo): # 选取当前胚料原材料 - bom_line = self.get_raw_bom(embryo) - vals = { - 'bom_id': self.id, - 'product_id': bom_line.id, - 'product_tmpl_id': bom_line.product_tmpl_id.id, - 'product_qty': bom_line.volume * bom_line.materials_type_id.density * 1000, - 'product_uom_id': bom_line.uom_id.id - } - return self.env['mrp.bom.line'].create(vals) + raw_bom_line = self.get_raw_bom(embryo) + if raw_bom_line: + bom_line = self.env['mrp.bom.line'].create({ + 'bom_id': self.id, + 'product_id': raw_bom_line.id, + 'product_tmpl_id': raw_bom_line.product_tmpl_id.id, + 'product_qty': round(embryo.volume / 1000000000 * raw_bom_line.materials_type_id.density, 2), + 'product_uom_id': raw_bom_line.uom_id.id, + }) + return bom_line + else: + return False # 查询材料型号默认排第一的供应商 def get_supplier(self, materials_type): diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index d79dc323..6746f45a 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -12,8 +12,10 @@ - - + + + + diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py index 7a15fd2f..5428534d 100644 --- a/sf_manufacturing/models/model_type.py +++ b/sf_manufacturing/models/model_type.py @@ -1,4 +1,4 @@ -from odoo import api, fields, models +from odoo import fields, models class ModelType(models.Model): diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py index 60ec21f6..441fddf3 100644 --- a/sf_manufacturing/models/mrp_routing_workcenter.py +++ b/sf_manufacturing/models/mrp_routing_workcenter.py @@ -1,4 +1,4 @@ -from odoo import fields, models, api +from odoo import fields, models class ResMrpRoutingWorkcenter(models.Model): diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index f9f518c1..5b266a20 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -1,4 +1,5 @@ -from odoo import api, fields, models, _ +from odoo import api, fields, models +from datetime import datetime from collections import defaultdict from odoo.addons.resource.models.resource import Intervals diff --git a/sf_manufacturing1.zip b/sf_manufacturing1.zip deleted file mode 100644 index 3dfa3174..00000000 Binary files a/sf_manufacturing1.zip and /dev/null differ diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 02ffc7b6..aadd956e 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -1,7 +1,5 @@ from odoo import models, fields -from odoo.exceptions import ValidationError import datetime -import logging class ReSaleOrder(models.Model): @@ -15,16 +13,16 @@ class ReSaleOrder(models.Model): # 业务平台分配工厂后在智能工厂先创建销售订单 def sale_order_create(self, company_id, delivery_name, delivery_telephone, delivery_address, - deadline_of_delivery, user_id): + deadline_of_delivery): now_time = datetime.datetime.now() - partner = self.env.user.partner_id + partner = self.get_customer() order_id = self.env['sale.order'].sudo().create({ 'company_id': company_id.id, 'date_order': now_time, 'name': self.env['ir.sequence'].next_by_code('sale.order', sequence_date=now_time), 'partner_id': partner.id, 'state': 'draft', - 'user_id': user_id.id, + # 'user_id': user_id.id, 'person_of_delivery': delivery_name, 'telephone_of_delivery': delivery_telephone, 'address_of_delivery': delivery_address, @@ -32,16 +30,24 @@ class ReSaleOrder(models.Model): }) return order_id + def get_customer(self): + customer = self.env['res.partner'].search([('name', '=', '业务平台')]) + if customer: + return customer + else: + partner = self.env['res.partner'].create({'name': '业务平台'}) + return partner + # 业务平台分配工厂时在创建完产品后再创建销售明细信息 def sale_order_create_line(self, product, item): vals = { 'order_id': self.id, 'product_id': product.id, - 'name': '%s/%s/%s/%s/%s/%s' % ( + 'name': '%s/%s/%s/%s/±%s/%s' % ( product.model_long, product.model_width, product.model_height, product.model_volume, product.model_machining_precision, product.materials_id.name), 'price_unit': product.list_price, - 'product_uom_qty': item['number'] + 'product_uom_qty': item['number'], } return self.env['sale.order.line'].create(vals) diff --git a/sf_sale/views/sale_order_view.xml b/sf_sale/views/sale_order_view.xml index 819f073a..ae92e27f 100644 --- a/sf_sale/views/sale_order_view.xml +++ b/sf_sale/views/sale_order_view.xml @@ -9,6 +9,10 @@ + + +