diff --git a/quality_mrp_workorder/views/quality_views.xml b/quality_mrp_workorder/views/quality_views.xml index ce592e0b..09cc66fe 100644 --- a/quality_mrp_workorder/views/quality_views.xml +++ b/quality_mrp_workorder/views/quality_views.xml @@ -140,7 +140,4 @@ - - {'search_default_quality_checks': 1} - diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index b9d0184c..aa9df917 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -433,7 +433,6 @@ class MrpProduction(models.Model): # 工艺确认 def technology_confirm(self): process_parameters = [] - account_moves = [] purchase_orders = [] parameters_not = [] # 获取原有的工单对应的工序 @@ -464,6 +463,7 @@ class MrpProduction(models.Model): if account_moves: raise UserError(_("请联系工厂生产经理对该(%s)账单进行取消", ", ".join(account_moves))) + if purchase_orders: raise UserError(_("请联系工厂生产经理对该(%s)采购订单进行取消", ", ".join(purchase_orders))) if parameters_not: @@ -1543,23 +1543,27 @@ class MrpProduction(models.Model): picking_type_id = self._get_default_picking_type_id(vals.get('company_id', self.env.company.id)) vals['picking_type_id'] = picking_type_id vals['name'] = self.env['stock.picking.type'].browse(picking_type_id).sequence_id.next_by_id() - if not is_first: + product_id = self.env['product.product'].browse(vals['product_id']) + is_self_process = product_id.materials_type_id and product_id.materials_type_id.gain_way and product_id.materials_type_id.gain_way != '自加工' + if not is_first and is_self_process: is_first = True group_id = self.env["procurement.group"].create({'name': vals.get('name')}).id if not vals.get('procurement_group_id'): - product_id = self.env['product.product'].browse(vals['product_id']) if product_id.product_tmpl_id.single_manufacturing: - if product_id.categ_id.name == '成品': + + if product_id.categ_id.name == '成品' and is_self_process: + vals['procurement_group_id'] = group_id continue if product_id.id not in product_group_id.keys(): procurement_group_vals = self._prepare_procurement_group_vals(vals) - group_id = self.env["procurement.group"].create(procurement_group_vals).id - vals['procurement_group_id'] = group_id - product_group_id[product_id.id] = group_id + procurement_group_id = self.env["procurement.group"].create(procurement_group_vals).id + vals['procurement_group_id'] = procurement_group_id + product_group_id[product_id.id] = procurement_group_id else: vals['procurement_group_id'] = product_group_id[product_id.id] - vals['procurement_group_id'] = group_id + else: + vals['procurement_group_id'] = group_id return super(MrpProduction, self).create(vals_list) @api.depends('procurement_group_id.stock_move_ids.created_purchase_line_id.order_id', @@ -1729,7 +1733,12 @@ class sf_detection_result(models.Model): processing_panel = fields.Char('加工面') routing_type = fields.Selection([ ('装夹预调', '装夹预调'), - ('CNC加工', 'CNC加工')], string="工序类型") + ('CNC加工', 'CNC加工'), + ('解除装夹', '解除装夹'), + ('切割', '切割'), + ('表面工艺', '表面工艺'), + ('线切割', '线切割'), + ('人工线下加工', '人工线下加工')], string="工序类型") rework_reason = fields.Selection( [("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 2d4f1f9e..f88667a0 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1267,7 +1267,7 @@ class ResMrpWorkOrder(models.Model): record.production_id.process_state = '待加工' # 生成工件配送单 record.workpiece_delivery_ids = record._json_workpiece_delivery_list() - if record.routing_type == 'CNC加工': + if record.routing_type == 'CNC加工' or record.individuation_page_PTD is True: record.process_state = '待解除装夹' # record.write({'process_state': '待加工'}) record.production_id.process_state = '待解除装夹' @@ -1358,17 +1358,18 @@ class ResMrpWorkOrder(models.Model): # record.production_id.state = 'done' # ============工单完成,修改对应[质检单]的值===================== - if record.check_ids: + if record.check_ids.filtered(lambda qc: qc.quality_state in ('waiting', 'none')): + check_ids = record.check_ids.filtered(lambda qc: qc.quality_state in ('waiting', 'none')) if record.test_results == '合格': - record.check_ids.write({'test_results': None}) - for check_id in record.check_ids: + check_ids.write({'test_results': None}) + for check_id in check_ids: check_id.do_pass() elif record.test_results in ('返工', '报废'): - record.check_ids.write({ + check_ids.write({ 'test_results': record.test_results, 'reason': record.reason, 'detailed_reason': record.detailed_reason}) - for check_id in record.check_ids: + for check_id in check_ids: check_id.do_fail() # ====================================================== diff --git a/sf_manufacturing/models/purchase_order.py b/sf_manufacturing/models/purchase_order.py index c1f7cea8..313d2e73 100644 --- a/sf_manufacturing/models/purchase_order.py +++ b/sf_manufacturing/models/purchase_order.py @@ -4,6 +4,7 @@ from collections import defaultdict from odoo import api, fields, models, _ +from odoo.exceptions import UserError from odoo.tools import OrderedSet @@ -16,6 +17,20 @@ class PurchaseOrder(models.Model): compute='_compute_workorder_count', ) + def button_cancel(self): + account_moves = set() # 使用集合以避免重复,并提高查找速度 + accounts = self.env['account.move'].search( + [('id', 'in', self.invoice_ids.ids), ('state', 'not in', ['cancel', False])]) + + # 直接筛选掉状态为'cancel'或False的记录,避免多次迭代 + for account in accounts: + account_moves.add(account.name) # 使用set的add方法避免重复添加 + + # 如果你需要list形式的结果,可以将set转换为list + account_moves = list(account_moves) + if account_moves: + raise UserError(_("请联系工厂生产经理对该采购单的账单进行取消")) + return super(PurchaseOrder, self).button_cancel() def action_view_production(self): origins = [order.name for order in self.picking_ids] production_id = self.env['mrp.production'].search([('origin', 'in', origins)]) diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 18164796..ad2e7fe4 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -187,7 +187,7 @@ context="{'default_workcenter_id': workcenter_id}" class="btn-danger" attrs="{'invisible': ['|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '!=', 'blocked')]}"/>