diff --git a/sf_bf_connect/controllers/controllers.py b/sf_bf_connect/controllers/controllers.py index 4e9e44aa..ad85216f 100644 --- a/sf_bf_connect/controllers/controllers.py +++ b/sf_bf_connect/controllers/controllers.py @@ -19,6 +19,9 @@ class Sf_Bf_Connect(http.Controller): res = {'status': 1, 'factory_order_no': ''} logging.info('get_bfm_process_order_list:%s' % kw) try: + logging.info('get_bfm_process_order_list===================================:%s' % kw['order_number']) + # aa = request.env['sale.order'].sudo().get_default_code(kw['order_number']) + # datas = request.httprequest.data # ret = json.loads(datas) # ret = json.loads(ret['result']) @@ -101,6 +104,11 @@ class Sf_Bf_Connect(http.Controller): purchase_embryo) order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) res['factory_order_no'] = order_id.name + aa = request.env['sale.order'].sudo().search([('name', '=', order_id.name)]) + logging.info('get_bfm_process_or===================================:%s' % order_id.name) + aa.default_code = kw['order_number'] + logging.info('get_bfm_process_order_listaaaaaaaaaaaaaaaaaaaaaaaaaaaa================:%s' % aa.default_code) + except Exception as e: logging.info('get_bfm_process_order_list error:%s' % e) res['status'] = -1 diff --git a/sf_bf_connect/models/__init__.py b/sf_bf_connect/models/__init__.py index 1b8cfb6d..97a7ab84 100644 --- a/sf_bf_connect/models/__init__.py +++ b/sf_bf_connect/models/__init__.py @@ -1,4 +1,3 @@ from . import http from . import models - - +from . import process_status diff --git a/sf_bf_connect/models/process_status.py b/sf_bf_connect/models/process_status.py new file mode 100644 index 00000000..c89755ec --- /dev/null +++ b/sf_bf_connect/models/process_status.py @@ -0,0 +1,110 @@ +from odoo import api, fields, models, SUPERUSER_ID, _ +from odoo.exceptions import ValidationError +from datetime import datetime +import logging +from odoo.exceptions import UserError +import requests + +_logger = logging.getLogger(__name__) + +class StatusChange(models.Model): + _inherit = 'sale.order' + + default_code = fields.Char(string='内部编码') + + def action_confirm(self): + logging.info('函数已经执行=============') + if self._get_forbidden_state_confirm() & set(self.mapped('state')): + raise UserError(_( + "It is not allowed to confirm an order in the following states: %s", + ", ".join(self._get_forbidden_state_confirm()), + )) + logging.info('函数已经执行=============1') + for order in self: + if order.partner_id in order.message_partner_ids: + logging.info('函数已经执行=============2') + continue + order.message_subscribe([order.partner_id.id]) + logging.info('函数已经执行=============3') + self.write(self._prepare_confirmation_values()) + + # Context key 'default_name' is sometimes propagated up to here. + # We don't need it and it creates issues in the creation of linked records. + context = self._context.copy() + context.pop('default_name', None) + logging.info('函数已经执行=============4') + + self.with_context(context)._action_confirm() + if self.env.user.has_group('sale.group_auto_done_setting'): + logging.info('函数已经执行=============5') + self.action_done() + process_start_time = str(datetime.now()) + json1 = { + 'params': { + 'model_name': 'jikimo.process.order', + 'field_name': 'name', + # 'default_code': 'PO-2022-1214-0022', + 'default_code': self.default_code, + # 'default_code': self.name, + 'state': '加工中', + 'process_start_time': process_start_time, + }, + } + url1 = 'https://bfm.cs.jikimo.com/api/get/state/get_order' + requests.post(url1, json=json1, data=None) + logging.info('接口已经执行=============') + + return True + + def action_cancel(self): + """ Cancel SO after showing the cancel wizard when needed. (cfr `_show_cancel_wizard`) + + For post-cancel operations, please only override `_action_cancel`. + + note: self.ensure_one() if the wizard is shown. + """ + logging.info('函数已经执行=============') + cancel_warning = self._show_cancel_wizard() + logging.info('函数已经执行=============2') + json1 = { + 'params': { + 'model_name': 'jikimo.process.order', + 'field_name': 'name', + 'default_code': self.default_code, + # 'default_code': self.name, + 'state': '待派单', + }, + } + url1 = 'https://bfm.cs.jikimo.com/api/get/state/cancel_order' + requests.post(url1, json=json1, data=None) + if cancel_warning: + logging.info('函数已经执行=============3') + self.ensure_one() + logging.info('函数已经执行=============4') + template_id = self.env['ir.model.data']._xmlid_to_res_id( + 'sale.mail_template_sale_cancellation', raise_if_not_found=False + ) + lang = self.env.context.get('lang') + template = self.env['mail.template'].browse(template_id) + if template.lang: + lang = template._render_lang(self.ids)[self.id] + ctx = { + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_order_id': self.id, + 'mark_so_as_canceled': True, + 'default_email_layout_xmlid': "mail.mail_notification_layout_with_responsible_signature", + 'model_description': self.with_context(lang=lang).type_name, + } + return { + 'name': _('Cancel %s', self.type_name), + 'view_mode': 'form', + 'res_model': 'sale.order.cancel', + 'view_id': self.env.ref('sale.sale_order_cancel_view_form').id, + 'type': 'ir.actions.act_window', + 'context': ctx, + 'target': 'new' + } + else: + return self._action_cancel() + diff --git a/sf_manufacturing/models/__init__.py b/sf_manufacturing/models/__init__.py index 419dee46..a972aa8a 100644 --- a/sf_manufacturing/models/__init__.py +++ b/sf_manufacturing/models/__init__.py @@ -11,4 +11,3 @@ from . import res_user - diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 5a9c9d91..6a455c73 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -9,6 +9,13 @@ class ResWorkcenter(models.Model): users_ids = fields.Many2many("res.users", 'users_workcenter') + # @api.onchange('machine_tool_id') + # def get_machine_tool_is_binding(self): + # print('1111111') + # for item in self: + # item.machine_tool_id.is_binding = False + + equipment_ids = fields.One2many( 'maintenance.equipment', 'workcenter_id', string="Maintenance Equipment", check_company=True) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index a5e8cba6..9cef2bb2 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -258,9 +258,6 @@ class ResMrpWorkOrder(models.Model): else: return True - # def fetchCNCing(self): - # return None - # cnc程序获取 def fetchCNC(self): try: @@ -316,14 +313,50 @@ class ResMrpWorkOrder(models.Model): logging.info('fetchCNC error:%s' % e) raise UserError(e) - # return { - # 'name': _("工单"), - # 'view_mode': 'form', - # 'res_model': 'mrp.workorder', - # 'res_id': self.id, - # 'type': 'ir.actions.act_window', - # 'target': 'new' - # } + # cnc程序获取 + def fetchCNC(self): + cnc = self.env['mrp.workorder'].search( + [('routing_type', '=', 'CNC加工'), ('production_id', '=', self.production_id.id)], limit=1) + if cnc.product_id.upload_model_file: + attachment = cnc.product_id.upload_model_file[0] + base64_data = base64.b64encode(attachment.datas) + base64_datas = base64_data.decode('utf-8') + model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest() + res = {'model_code': '' if not cnc.product_id.upload_model_file else model_code, + 'production_no': self.production_id.name, + 'machine_tool_code': cnc.workcenter_id.machine_tool_id.code, + 'material_code': cnc.env['sf.production.materials'].search( + [('id', '=', cnc.product_id.materials_id.id)]).materials_no, + 'material_type_code': cnc.env['sf.materials.model'].search( + [('id', '=', cnc.product_id.materials_type_id.id)]).materials_no, + 'machining_processing_panel': cnc.product_id.model_processing_panel, + 'machining_precision': cnc.product_id.model_machining_precision, + 'embryo_long': cnc.product_id.bom_ids.bom_line_ids.product_id.length, + 'embryo_height': cnc.product_id.bom_ids.bom_line_ids.product_id.height, + 'embryo_width': cnc.product_id.bom_ids.bom_line_ids.product_id.width, + 'order_no': cnc.production_id.origin, + 'user': self.env.user.name, + 'model_file': '' if not cnc.product_id.model_file else base64.b64encode( + cnc.product_id.model_file).decode('utf-8') + } + logging.info('res:%s' % res) + configsettings = self.env['res.config.settings'].get_values() + config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) + url = '/api/intelligent_programming/create' + config_url = configsettings['sf_url'] + url + # res_str = json.dumps(res) + ret = requests.post(config_url, json={}, data=res, headers=config_header) + ret = ret.json() + if ret['status'] == 1: + self.write({'programming_no': ret['programming_no'], 'programming_state': '编程中', 'work_state': '编程中'}) + return { + 'name': _("工单"), + 'view_mode': 'form', + 'res_model': 'mrp.workorder', + 'res_id': self.id, + 'type': 'ir.actions.act_window', + 'target': 'new' + } def json_workorder_str1(self, k, production, route): workorders_values_str = [0, '', { @@ -436,7 +469,7 @@ class CNCprocessing(models.Model): cnc_workorder.state = 'done' cnc_workorder.work_state = '已编程' cnc_workorder.programming_state = '已编程' - cnc_workorder.time_ids.date_end = datetime.now() + # cnc_workorder.time_ids.date_end = datetime.now() def get_cnc_processing_file(self, folder_name, cnc_processing): logging.info('folder_name:%s' % folder_name) @@ -501,6 +534,9 @@ class SfWorkOrderBarcodes(models.Model): def on_barcode_scanned(self, barcode): tray_code = self.env['sf.tray'].search([('code', '=', barcode)]) - self.tray_code = tray_code.code + # 在这里,用等号赋值只是一次性的,只是一种展示 + # self.tray_code = tray_code.code + # 用write方法写入数据库是永久的 + self.write({'tray_code': tray_code.code}) workorder = self.env['mrp.workorder'].browse(self.ids) workorder.gettray_auto(barcode) diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index cee3c398..91a0dd91 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -8,6 +8,7 @@ + @@ -31,6 +32,22 @@ + + {'invisible': ['|', '|', '|','|', ('production_state','in', ('draft', 'done', + 'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done', 'cancel')), + ('is_user_working', '!=', False),("user_permissions","=",False)]} + + + + + + + + + + + + @@ -80,8 +97,6 @@ - - @@ -99,7 +114,9 @@ - + + + @@ -221,6 +238,10 @@ + + + @@ -260,7 +281,6 @@ - + @@ -280,6 +301,16 @@ string="打印标签" attrs='{"invisible": [("user_permissions","=",False)]}'/> + + + + + + + >>>>>>> 3d882f5492685cfdb3cd9960bd24cdf9ef247f79 +