From 9f9c08b1f004d90e3747805bd96bb07b0f6e4a36 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Mon, 21 Apr 2025 14:35:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jikimo_purchase_request/models/mrp_production.py | 2 +- sf_manufacturing/models/mrp_production.py | 1 + sf_manufacturing/models/purchase_request_line.py | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/jikimo_purchase_request/models/mrp_production.py b/jikimo_purchase_request/models/mrp_production.py index c1c0feb9..4ae6bd61 100644 --- a/jikimo_purchase_request/models/mrp_production.py +++ b/jikimo_purchase_request/models/mrp_production.py @@ -20,7 +20,7 @@ class MrpProduction(models.Model): 采购请求 """ self.ensure_one() - pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name)]) + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name),('is_subcontract', '!=', True)]) action = { 'res_model': 'purchase.request', 'type': 'ir.actions.act_window', diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 02125aca..667251f9 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -922,6 +922,7 @@ class MrpProduction(models.Model): "requested_by": self.env.context.get("uid", self.env.uid), "assigned_to": False, "bom_id": self[0].bom_id.id, + "is_subcontract":True, }) for product_id, request_line_list in grouped_purchase_request_line_sorted_list.items(): cur_request_line = request_line_list[0] diff --git a/sf_manufacturing/models/purchase_request_line.py b/sf_manufacturing/models/purchase_request_line.py index 385594e4..b08bb3e7 100644 --- a/sf_manufacturing/models/purchase_request_line.py +++ b/sf_manufacturing/models/purchase_request_line.py @@ -17,6 +17,9 @@ from odoo.exceptions import UserError, ValidationError from odoo.tools import float_compare, float_round, float_is_zero, format_datetime +class PurchaseRequestLine(models.Model): + _inherit = 'purchase.request' + is_subcontract = fields.Boolean(string='是否外协',default=False) class PurchaseRequestLine(models.Model): _inherit = 'purchase.request.line' is_subcontract = fields.Boolean(string='是否外协') From 7d70184a5dad877e8783a9273631b7c76cb05228 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Mon, 21 Apr 2025 14:55:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A4=96=E5=8D=8F=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 35 ++++++++++++++++++- sf_manufacturing/views/mrp_workorder_view.xml | 11 ++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 8d5ecbf1..15369f8d 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -69,7 +69,18 @@ class ResMrpWorkOrder(models.Model): delivery_warning = fields.Selection([('normal', '正常'), ('warning', '告警'), ('overdue', '逾期')], string='时效', tracking=True) back_button_display = fields.Boolean(default=False, compute='_compute_back_button_display', store=True) - + pr_mp_count = fields.Integer('采购申请单数量', compute='_compute_pr_mp_count', store=True) + @api.depends('state') + def _compute_pr_mp_count(self): + for item in self: + if not item.is_subcontract: + pr_mp_count = 0 + continue + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name),('is_subcontract','=','True')]) + if pr_ids: + item.pr_mp_count = len(pr_ids) + else: + item.pr_mp_count = 0 @api.depends('state') def _compute_back_button_display(self): for record in self: @@ -445,6 +456,28 @@ class ResMrpWorkOrder(models.Model): else: order.surface_technics_purchase_count = 0 + def action_view_pr_mrp_workorder(self): + """ + 采购请求 + """ + self.ensure_one() + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name),('is_subcontract', '=', True)]) + action = { + 'res_model': 'purchase.request', + 'type': 'ir.actions.act_window', + } + if len(pr_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': pr_ids[0].id, + }) + else: + action.update({ + 'name': _("从 %s生成采购请求单", self.name), + 'domain': [('id', 'in', pr_ids)], + 'view_mode': 'tree,form', + }) + return action def action_view_surface_technics_purchase(self): self.ensure_one() # if self.routing_type == '表面工艺': diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index c1f165fd..1720a418 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -144,6 +144,17 @@ statusbar_visible="pending,waiting,ready,progress,to be detected,done,rework"/> +