diff --git a/sf_dlm/models/product_supplierinfo.py b/sf_dlm/models/product_supplierinfo.py index 4141a363..2784cba0 100644 --- a/sf_dlm/models/product_supplierinfo.py +++ b/sf_dlm/models/product_supplierinfo.py @@ -37,7 +37,7 @@ class ResMrpBomMo(models.Model): 'product_qty': 1, 'product_uom_id': 1 } - return self.env['mrp.bom.line'].create(vals) + return self.env['mrp.bom.line'].sudo().create(vals) # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom def bom_create(self, product, bom_type, product_type): @@ -64,7 +64,7 @@ class ResMrpBomMo(models.Model): qty = 1 if round(embryo.volume * raw_bom_line.materials_type_id.density / 1000000) > 1: qty = round(embryo.volume * raw_bom_line.materials_type_id.density / 1000000) - bom_line = self.env['mrp.bom.line'].create({ + bom_line = self.env['mrp.bom.line'].sudo().create({ 'bom_id': self.id, 'product_id': raw_bom_line.id, 'product_tmpl_id': raw_bom_line.product_tmpl_id.id, diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 82588ffe..e2d6616a 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -56,8 +56,9 @@ class MrpProduction(models.Model): glb_file = fields.Binary("glb模型文件") production_line_id = fields.Many2one('sf.production.line', string='生产线') plan_start_processing_time = fields.Datetime('计划开始加工时间') - production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')], - string='上/下产线', default='待上产线') + production_line_state = fields.Selection( + [('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')], + string='上/下产线', default='待上产线') # 工序状态 # Todo 研究下用法 process_state = fields.Selection([ @@ -114,7 +115,7 @@ class MrpProduction(models.Model): # production.state = 'pending_processing' production.state = 'pending_cam' if production.state == 'progress' and production.schedule_state == '已排' and production.process_state == '待加工': - # if production.state == 'pending_cam' and production.process_state == '待加工': + # if production.state == 'pending_cam' and production.process_state == '待加工': production.state = 'pending_processing' elif production.state == 'progress' and production.process_state == '待解除装夹': production.state = 'pending_era_cam' @@ -262,10 +263,14 @@ class MrpProduction(models.Model): # 其他规则限制: 默认只分配给工作中心状态为非故障的工作中心; def _create_workorder3(self): + programming_no = None + product_id_new = None for production in self: if not production.bom_id or not production.product_id: continue workorders_values = [] + if product_id_new is None: + product_id_new = production.product_id product_qty = production.product_uom_id._compute_quantity(production.product_qty, production.bom_id.product_uom_id) @@ -290,7 +295,14 @@ class MrpProduction(models.Model): 'state': 'pending', }] if production.product_id.categ_id.type == '成品': - production.fetchCNC() + if programming_no is None: + production.fetchCNC() + programming_no = production.programming_no + else: + if production.product_id == product_id_new: + if not production.programming_no: + production.write({'programming_no': programming_no, 'programming_state': '编程中'}) + # 根据加工面板的面数及对应的工序模板生成工单 i = 0 processing_panel_len = len(production.product_id.model_processing_panel.split(',')) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 1ce57f85..590903d3 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -736,14 +736,17 @@ class ResMrpWorkOrder(models.Model): if self.routing_type == '装夹预调' and self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name: self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name if self.routing_type == '装夹预调': - if not self.cnc_ids: + cnc_workorder = self.search( + [('production_id', '=', self.production_id.id), ('routing_type', '=', 'CNC加工')], + limit=1, order='id asc') + if not cnc_workorder: raise UserError(_('该制造订单还未下发CNC程序,请稍后再试')) else: - for item in self.cnc_ids: + for item in cnc_workorder.cnc_ids: functional_cutting_tool = self.env['sf.functional.cutting.tool.entity'].search( [('tool_name_id.name', '=', item.cutting_tool_name)]) if not functional_cutting_tool: - raise UserError(_('该制造订单的CNC程序为%s没有对应的功能刀具%s' % item.cutting_tool_name)) + raise UserError(_('该制造订单的CNC程序为%s没有对应的功能刀具' % item.cutting_tool_name)) if self.routing_type == '解除装夹': ''' 记录开始时间 diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index c6d0788a..7fdf390d 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -612,6 +612,7 @@ + diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 99af4c0f..64c64b52 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -85,9 +85,9 @@ class ReSaleOrder(models.Model): self.check_status = 'pending' def get_customer(self): - partner_tag = self.env['res.partner.category'].search([('name', '=', '业务平台')], limit=1, order='id asc') + partner_tag = self.env['res.partner.category'].sudo().search([('name', '=', '业务平台')], limit=1, order='id asc') if not partner_tag: - partner_tag = self.env['res.partner.category'].create({'name': '平台客户'}) + partner_tag = self.env['res.partner.category'].sudo().create({'name': '平台客户'}) customer = self.env['res.partner'].search([('name', '=', '业务平台')], limit=1, order='id asc') if customer: if not customer.vat: