diff --git a/sf_base/models/sf_base.py b/sf_base/models/sf_base.py index d10f190e..c8f5a53d 100644 --- a/sf_base/models/sf_base.py +++ b/sf_base/models/sf_base.py @@ -252,6 +252,7 @@ class CNCprocessing(models.Model): _name = 'cnc.processing' _description = "CNC加工" + cnc_id = fields.Many2one('ir.attachment') FNo = fields.Char(string="序号") FPGName = fields.Char(string="程序名") FKnifeName = fields.Char(string="刀具名称") diff --git a/sf_base/views/mrs_common_view.xml b/sf_base/views/mrs_common_view.xml index 748b0683..452bd664 100644 --- a/sf_base/views/mrs_common_view.xml +++ b/sf_base/views/mrs_common_view.xml @@ -296,7 +296,6 @@ - diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index 10b1dc94..77cf7c7a 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -4,13 +4,10 @@ import base64 import logging import math - - from io import BytesIO -from odoo import api, fields, models,SUPERUSER_ID +from odoo import api, fields, models, SUPERUSER_ID from pystrich.code128 import Code128Encoder - _logger = logging.getLogger(__name__) @@ -84,7 +81,6 @@ class MrpWorkOrder(models.Model): _inherit = 'mrp.workorder' _description = '工单' - tray_ids = fields.One2many('sf.tray', 'workorder_id', string='托盘') # def get_tray_info(self): # @api.onchange('X_axis', 'Y_axis', 'Z_axis') @@ -129,7 +125,8 @@ class MrpWorkOrder(models.Model): # 扫码绑定托盘方法 def gettray(self): return "" - #解除托盘绑定 + + # 解除托盘绑定 def unbindtray(self): return "" @@ -176,37 +173,70 @@ class MrpWorkOrder(models.Model): cnc_ids = fields.One2many("cnc.processing", 'workorder_id', string="CNC加工") - # @api.depends('tray_id') - # def updateTrayState(self): - # - # for item in self: - # if item.tray_code == False: - # continue - # trayInfo = self.env['sf.tray'].sudo.search([('code', '=', item.tray_code)]) - # if trayInfo: - # trayInfo.update( - # { - # 'production_id': item.production_id, - # 'state': "占用", - # } - # ) + tray_code = fields.Char( string="托盘",compute='updateTrayState') + + + @api.depends('tray_code') + def updateTrayState(self): + tray = self.env['sf.tray'].search([("code",'=',self.tray_code)]) + if tray: + tray.workorder_id = self + else: + return "" + def recreateManufacturing(self): + """ + 重新生成制造订单 + """ + values = self.env['mrp.production'].create_production1_values(self.production_id) + productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(self.production_id.company_id).create( + values) + self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) + self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) + productions._create_workorder() + productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \ + ( + p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm() + for production in productions: + origin_production = production.move_dest_ids and production.move_dest_ids[ + 0].raw_material_production_id or False + orderpoint = production.orderpoint_id + if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual': + production.message_post( + body=_('This production order has been created from Replenishment Report.'), + message_type='comment', + subtype_xmlid='mail.mt_note') + elif orderpoint: + production.message_post_with_view( + 'mail.message_origin_link', + values={'self': production, 'origin': orderpoint}, + subtype_id=self.env.ref('mail.mt_note').id) + elif origin_production: + production.message_post_with_view( + 'mail.message_origin_link', + values={'self': production, 'origin': origin_production}, + subtype_id=self.env.ref('mail.mt_note').id) - # productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(self.company_id).create(self.production_id) # print(productions) return "" def recreateWorkerOrder(self): - self.env['stock.move'].sudo().create(self.production_id._get_moves_raw_values()) - self.env['stock.move'].sudo().create(self.production_id._get_moves_finished_values()) - self.production_id._create_workorder() + """ + 返工重新生成工单 + """ + productions = self.production_id + self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) + self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) + productions.create_workorder1(self.processing_panel) return "" - cnc_id = fields.Many2many('ir.attachment', 'cnc_attachment', string="cnc程序获取") + + def fetchCNC(self): return "" + ''' 制造订单绑定托盘信息 ''' @@ -215,12 +245,83 @@ class MrpWorkOrder(models.Model): class MrpProduction(models.Model): _inherit = 'mrp.production' _description = "制造订单" - tray_ids = fields.One2many('sf.tray', 'production_id', string="托盘") + + + def create_production1_values(self, production): + production_values_str = {'origin': production.origin, + 'product_id': production.product_id.id, + 'product_description_variants': production.product_description_variants, + 'product_qty': production.product_qty, + 'product_uom_id': production.product_uom_id.id, + 'location_src_id': production.location_src_id.id, + 'location_dest_id': production.location_dest_id.id, + 'bom_id': production.bom_id.id, + 'date_deadline': production.date_deadline, + 'date_planned_start': production.date_planned_start, + 'date_planned_finished': production.date_planned_finished, + 'procurement_group_id': False, + 'propagate_cancel': production.propagate_cancel, + 'orderpoint_id': production.orderpoint_id.id, + 'picking_type_id': production.picking_type_id.id, + 'company_id': production.company_id.id, + 'move_dest_ids': production.move_dest_ids.ids, + 'user_id': production.user_id.id} + return production_values_str + + def create_workorder1(self, k): + for production in self: + if not production.bom_id or not production.product_id: + continue + workorders_values = [] + + product_qty = production.product_uom_id._compute_quantity(production.product_qty, + production.bom_id.product_uom_id) + exploded_boms, dummy = production.bom_id.explode(production.product_id, + product_qty / production.bom_id.product_qty, + picking_type=production.bom_id.picking_type_id) + + for bom, bom_data in exploded_boms: + # If the operations of the parent BoM and phantom BoM are the same, don't recreate work orders. + if not (bom.operation_ids and (not bom_data['parent_line'] or bom_data[ + 'parent_line'].bom_id.operation_ids != bom.operation_ids)): + continue + for operation in bom.operation_ids: + if operation._skip_operation_line(bom_data['product']): + continue + workorders_values += [{ + 'name': operation.name, + 'production_id': production.id, + 'workcenter_id': operation.workcenter_id.id, + 'product_uom_id': production.product_uom_id.id, + 'operation_id': operation.id, + 'state': 'pending', + }] + # 根据加工面板的面数及对应的工序模板生成工单 + i = 0 + production.product_id.model_processing_panel = k + processing_panel_len = len(k) + for k in (production.product_id.model_processing_panel.split(',')): + routingworkcenter = self.env['sf.model.type.routing.sort'].search( + [('model_type_id', '=', production.product_id.model_type_id.id)], + + order='sequence asc' + ) + i += 1 + for route in routingworkcenter: + + if route.is_repeat == True: + workorders_values.append( + self.env['mrp.workorder'].json_workorder_str(k, production, route)) + + production.workorder_ids = workorders_values + for workorder in production.workorder_ids: + workorder.duration_expected = workorder._get_duration_expected() + + class Attachment(models.Model): _inherit = 'ir.attachment' cnc_model = fields.Binary('cnc文件', attachment=False) model_name = fields.Char('模型名称') - diff --git a/sf_route_workcenter/report/sf_tray_report.xml b/sf_route_workcenter/report/sf_tray_report.xml index d1af6676..f0bcc642 100644 --- a/sf_route_workcenter/report/sf_tray_report.xml +++ b/sf_route_workcenter/report/sf_tray_report.xml @@ -1,6 +1,6 @@ - + Dymo Label Sheet @@ -16,6 +16,7 @@ 96 + 打印条形码 sf.tray @@ -27,7 +28,7 @@ - +