diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py index 7352396d..aae20018 100644 --- a/sf_base/__manifest__.py +++ b/sf_base/__manifest__.py @@ -16,7 +16,6 @@ 'security/ir.model.access.csv', 'views/mrs_base_view.xml', 'views/mrs_common_view.xml', - 'views/mrp_routing_workcenter_view.xml', "views/menu_view.xml", 'views/sale_order_view.xml', 'views/product_template_view.xml', diff --git a/sf_base/models/process.py b/sf_base/models/process.py index e6ef6348..ec793560 100644 --- a/sf_base/models/process.py +++ b/sf_base/models/process.py @@ -6,6 +6,7 @@ class ModelType(models.Model): _description = '模型类型' name = fields.Char('名称') + embryo_tolerance = fields.Integer('胚料的容余量') routing_tmpl_ids = fields.One2many('sf.model.type.routing.sort', 'model_type_id', '工序模板') diff --git a/sf_base/models/product_template.py b/sf_base/models/product_template.py index 99ab1f81..02bc0bad 100644 --- a/sf_base/models/product_template.py +++ b/sf_base/models/product_template.py @@ -1,4 +1,4 @@ -from odoo import models, fields,api +from odoo import models, fields, api from odoo.exceptions import ValidationError @@ -9,7 +9,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³]', digits=(16, 3)) + model_volume = fields.Float('模型体积[mm³]', digits=(16, 3), compute='_compute_model_volume', store=True) model_precision = fields.Float('精度要求', digits=(16, 3)) model_materials_id = fields.Many2one('mrs.production.materials', string='模型材料') model_materials_type_id = fields.Many2one('mrs.materials.model', string='模型材料型号') @@ -22,6 +22,7 @@ class ResProductTemplate(models.Model): # total_amount = fields.Float('金额', digits=(16, 3), compute='_compute_total_amount') # model_number = + # 胚料的长,宽,高 embryo_long = fields.Float('胚料长[mm]', digits=(16, 3), onchange='count_embryo_size') embryo_width = fields.Float('胚料宽[mm]', digits=(16, 3), onchange='count_embryo_size') @@ -29,6 +30,12 @@ class ResProductTemplate(models.Model): embryo_materials_id = fields.Many2one('mrs.production.materials', string='胚料材料') embryo_materials_type_id = fields.Many2one('mrs.materials.model', string='胚料材料型号') + long = fields.Float('长[mm]', digits=(16, 3), onchange='add_product_size') + width = fields.Float('宽[mm]', digits=(16, 3), onchange='add_product_size') + height = fields.Float('高[mm]', digits=(16, 3), onchange='add_product_size') + materials_id = fields.Many2one('mrs.production.materials', string='材料') + materials_type_id = fields.Many2one('mrs.materials.model', string='材料型号') + volume = fields.Float(compute='_compute_volume', store=True) @@ -36,6 +43,10 @@ class ResProductTemplate(models.Model): def _compute_volume(self): self.volume = self.embryo_long * self.embryo_width * self.embryo_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() @@ -63,6 +74,7 @@ class ResProductTemplate(models.Model): copy_product_id.sudo().write(vals) return copy_product_id + # 在产品上增加模型类型和加工的面(例如:A、B) , # 并根据模型类型计算出产品的胚料尺寸; @api.onchange('model_type_id') @@ -82,6 +94,25 @@ class ResProductTemplate(models.Model): + # 根据模型类型默认给模型的长高宽加配置的长度; + @api.onchange('model_type_id') + def add_product_size(self): + if not self.model_type_id: + return + model_type = self.env['sf.model.type'].search( + [('id', '=', self.model_type_id.id)]) + print(self.model_long) + print(self.model_width) + print(self.model_height) + for item in self: + print(item.model_long) + print(item.model_width) + print(item.model_height) + item.model_long = item.model_long + model_type.embryo_tolerance + item.model_width = item.model_width + model_type.embryo_tolerance + item.model_height = item.model_width + model_type.embryo_tolerance + + class ResProductCategory(models.Model): _inherit = "product.category" @@ -124,14 +155,3 @@ class ResMrpBom(models.Model): 'product_uom_id': 1 } return self.env['mrp.bom.line'].create(vals) - - - - - - - - - - - diff --git a/sf_base/models/sf_base.py b/sf_base/models/sf_base.py index e337d301..d098127b 100644 --- a/sf_base/models/sf_base.py +++ b/sf_base/models/sf_base.py @@ -264,5 +264,5 @@ class CNCprocessing(models.Model): FJGSD = fields.Char(string="加工深度(Z)") FSCCD = fields.Char(string="刀具伸出长度") FDJSpec = fields.Char(string="刀柄型号") - FJGDate = fields.Char(string="预计加工时间") + FJGDate = fields.Datetime(string="预计加工时间") FComment = fields.Char(string="备注") diff --git a/sf_base/views/mrp_routing_workcenter_view.xml b/sf_base/views/mrp_routing_workcenter_view.xml deleted file mode 100644 index f094c22d..00000000 --- a/sf_base/views/mrp_routing_workcenter_view.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - #-----------------作业------------------- - - mrp.routing.workcenter.form.inherit.sf - mrp.routing.workcenter - - - - - - - - - - - - - #-----------------工单------------------- - - mrp.production.workorder.form.inherit.sf - mrp.workorder - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #-----------------制造订单里的工单------------------- - - mrp.production.workorder.tree.editable.inherit.sf - mrp.workorder - - - - - - - - - \ No newline at end of file diff --git a/sf_base/views/mrs_base_view.xml b/sf_base/views/mrs_base_view.xml index 4cff9e87..927cc8dc 100644 --- a/sf_base/views/mrs_base_view.xml +++ b/sf_base/views/mrs_base_view.xml @@ -531,12 +531,16 @@
+ - + + + + diff --git a/sf_manufacturing_orders/__manifest__.py b/sf_manufacturing_orders/__manifest__.py index 7958836b..b409bc12 100644 --- a/sf_manufacturing_orders/__manifest__.py +++ b/sf_manufacturing_orders/__manifest__.py @@ -10,9 +10,10 @@ """, 'category': '', 'website': 'https://www.sf.jikimo.com', - 'depends': ['mrp'], + 'depends': ['mrp', 'sf_base', 'sf_route_workcenter'], 'data': [ 'views/sf_production.xml', + 'views/mrp_routing_workcenter_view.xml' diff --git a/sf_manufacturing_orders/models/__init__.py b/sf_manufacturing_orders/models/__init__.py index 28bfd6c0..38af3ba7 100644 --- a/sf_manufacturing_orders/models/__init__.py +++ b/sf_manufacturing_orders/models/__init__.py @@ -1,3 +1,4 @@ from . import sf_production from . import mrp_workorder + diff --git a/sf_mrs_connect/__manifest__.py b/sf_mrs_connect/__manifest__.py index 7f28c5ee..5003bd36 100644 --- a/sf_mrs_connect/__manifest__.py +++ b/sf_mrs_connect/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'YZ', 'website': 'https://www.sf.cs.jikimo.com', - 'depends': [], + 'depends': ['sf_base'], 'data': [ # 'views/sale_process_order_view.xml' ], diff --git a/sf_mrs_connect/controllers/__init__.py b/sf_mrs_connect/controllers/__init__.py index e69de29b..e046e49f 100644 --- a/sf_mrs_connect/controllers/__init__.py +++ b/sf_mrs_connect/controllers/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index e046e49f..5d6e8160 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -1 +1,27 @@ -from . import controllers +# -*- coding: utf-8 -*- +import json +import logging +from datetime import date, timedelta +from odoo import http +from odoo.http import request + + +class Sf_Mrs_Connect(http.Controller): + + @http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + cors="*") + def get_cnc_processing_create(self, **kw): + """ + 获取mrs下发的编程单 + :param kw: + :return: + """ + logging.info('get_cnc_processing_create:%s' % kw) + try: + datas = request.httprequest.data + ret = json.loads(datas) + ret = json.loads(ret['result']) + for obj in ret: + request.env['cnc.processing'].with_user(request.env.ref("base.user_admin")).CNCprocessing_create(obj) + except Exception as e: + logging.info('get_cnc_processing_create error:%s' % e) diff --git a/sf_route_workcenter/__manifest__.py b/sf_route_workcenter/__manifest__.py index 5d8e16ca..899a5e4f 100644 --- a/sf_route_workcenter/__manifest__.py +++ b/sf_route_workcenter/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'YZ', 'website': 'https://www.sf.cs.jikimo.com', - 'depends': ['mrp', 'sf_base', 'hr_holidays', 'maintenance'], + 'depends': ['mrp', 'sf_base', 'hr_holidays', 'maintenance', 'sf_manufacturing_orders'], 'data': [ 'views/sf_tray_view.xml', 'views/sf_workorder.xml', diff --git a/sf_route_workcenter/models/mrp_maintenance.py b/sf_route_workcenter/models/mrp_maintenance.py index d0ea9b42..8456c179 100644 --- a/sf_route_workcenter/models/mrp_maintenance.py +++ b/sf_route_workcenter/models/mrp_maintenance.py @@ -15,6 +15,8 @@ from odoo.addons.resource.models.resource import Intervals class MrpWorkcenter(models.Model): _inherit = "mrp.workcenter" + machine_tool_id = fields.Many2one('mrs.machine_tool', '机床') + equipment_ids = fields.One2many( 'maintenance.equipment', 'workcenter_id', string="Maintenance Equipment", check_company=True) diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index 6b74e543..1cff9861 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -3,13 +3,16 @@ import base64 import logging import math - +import json +import requests from io import BytesIO from odoo import api, fields, models, SUPERUSER_ID, _ from pystrich.code128 import Code128Encoder from odoo.exceptions import ValidationError from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta +from odoo.addons.sf_base.commons.common import Common + _logger = logging.getLogger(__name__) @@ -19,6 +22,26 @@ class CNCprocessing(models.Model): workorder_id = fields.Many2one('mrp.workorder', string="工单") + # mrs下发编程单创建CNC加工 + def CNCprocessing_create(self, obj): + workorder = self.env['mrp.workorder'].search([('production_id', '=', obj['manufacturing_order_no']), + ('processing_panel', '=', obj['processing_panel']), + ('routing_type', '=', 'CNC加工')]) + self.env['cnc.processing'].create({ + 'workorder_id': workorder.id, + 'FNo': obj['sequence_number'], + 'FPGName': obj['program_name'], + 'FKnifeName': obj['cutting_tool_name'], + 'FDNo': obj['cutting_tool_no'], + 'FWorkType': obj['processing_type'], + 'FXY': obj['margin_x_y'], + 'FZ': obj['margin_z'], + 'FJGSD': obj['depth_of_processing_z'], + 'FSCCD': obj['cutting_tool_extension_length'], + 'FDJSpec': obj['cutting_tool_handle_type'], + # 'FJGDate': obj[''] + }) + class Tray(models.Model): _inherit = 'sf.tray' @@ -83,11 +106,6 @@ class MrpWorkOrder(models.Model): _inherit = 'mrp.workorder' _description = '工单' - - - - - def button_start(self): if self.state == 'waiting': self.ensure_one() @@ -133,7 +151,9 @@ class MrpWorkOrder(models.Model): if self.date_planned_finished and self.date_planned_finished < start_date: vals['date_planned_finished'] = start_date return self.write(vals) - else:raise ValidationError(_('请先完成上一步工单')) + else: + raise ValidationError(_('请先完成上一步工单')) + # def get_tray_info(self): # @api.onchange('X_axis', 'Y_axis', 'Z_axis') # def get_center_point(self): @@ -290,8 +310,31 @@ class MrpWorkOrder(models.Model): else: return True + # cnc程序获取 + def fetchCNC(self): - return "" + res = [{'model_code': self.product_id.barcode, 'production_no': self.production_id.name, + 'machine_tool_code': self.workcenter_id.machine_tool_id.code, + 'material_code': self.env['mrs.production.materials'].search( + [('id', '=', self.product_id.materials_id.id)]).materials_no, + 'material_type_code': self.env['mrs.materials.model'].search( + [('id', '=', self.product_id.materials_type_id.id)]).materials_no, + 'embryo_long': self.product_id.bom_ids.bom_line_ids.product_id.long, + 'embryo_height': self.product_id.bom_ids.bom_line_ids.product_id.height, + 'embryo_width': self.product_id.bom_ids.bom_line_ids.product_id.width + # 'factory_code': self.env.user.company_id.partner_id. + }] + configsettings = self.env['res.config.settings'].get_values() + config_header = Common.get_headers(self, configsettings['token'], configsettings['mrs_secret_key']) + url = '/api/intelligent_programming/create' + config_url = configsettings['mrs_url'] + url + res_str = json.dumps(res) + ret = requests.post(config_url, json={"result": res_str}, data=None, headers=config_header) + ret = ret.json() + result = json.loads(ret['result']) + if result['status'] == 1: + return self.write({'state': 'progress'}) + def json_workorder_str1(self, k, production, route): workorders_values_str = [0, '', { 'product_uom_id': production.product_uom_id.id, @@ -340,14 +383,13 @@ class MrpProduction(models.Model): 'user_id': production.user_id.id} return production_values_str - def _reset_work_order_sequence1(self,k): + def _reset_work_order_sequence1(self, k): for rec in self: current_sequence = 1 for work in rec.workorder_ids: work.sequence = current_sequence current_sequence += 1 - def _create_workorder1(self, k): for production in self: if not production.bom_id or not production.product_id: @@ -389,11 +431,10 @@ class MrpProduction(models.Model): i += 1 for route in routingworkcenter: - if route.routing_type == '后置三元质量检测': workorders_values.append( self.env['mrp.workorder'].json_workorder_str1(k, production, route) - ) + ) if route.routing_type == 'CNC加工': workorders_values.append( self.env['mrp.workorder'].json_workorder_str1(k, production, route)) @@ -406,6 +447,3 @@ class MrpProduction(models.Model): res = self._create_workorder1(k) self._reset_work_order_sequence1(k) return res - - -