From de951b1b45f306ea82b1f129fe0d477a761dba22 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 3 Jun 2025 16:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E9=BD=90=E5=A5=97=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/sf_production_demand_plan.py | 94 +++++++++++++++++-- sf_demand_plan/views/demand_plan.xml | 7 ++ 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 44243fdb..37701de2 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -105,6 +105,18 @@ class sf_production_plan(models.Model): default=False ) + hide_action_purchase_orders = fields.Boolean( + string='显示采购按钮', + compute='_compute_hide_action_purchase_orders', + default=False + ) + + hide_action_stock_picking = fields.Boolean( + string='显示调拨单按钮', + compute='_compute_hide_action_stock_picking', + default=False + ) + @api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line', 'sale_order_id.mrp_production_ids.state') def _compute_status(self): @@ -327,14 +339,6 @@ class sf_production_plan(models.Model): 'target': 'new', } - def action_open_sale_order(self): - return { - 'type': 'ir.actions.act_window', - 'res_model': 'sale.order', - 'res_id': self.sale_order_id.id, - 'view_mode': 'form', - } - @api.depends('sale_order_id.mrp_production_ids.state') def _compute_hide_action_open_mrp_production(self): for record in self: @@ -344,7 +348,45 @@ class sf_production_plan(models.Model): record.hide_action_open_mrp_production = bool(mrp_production_ids) and record.supply_method in ( 'automation', 'manual') + def _compute_hide_action_purchase_orders(self): + for record in self: + record.hide_action_purchase_orders = False + if record.material_check == '0' and not record.sale_order_line_id.is_incoming_material: + mrp_production = record.sale_order_id.mrp_production_ids.filtered( + lambda p: p.product_id.id == record.product_id.id + ).sorted(key=lambda p: p.id) + if mrp_production: + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', mrp_production[0].name)]) + raw_materials = mrp_production.mapped('move_raw_ids.product_id') + if raw_materials: + purchase_orders = self.env['purchase.order'].sudo().search([ + ('state', '=', 'purchase'), + ('order_line.product_id', 'in', raw_materials.ids) + ]) + total_purchase_quantity = sum( + line.product_qty for order in purchase_orders for line in order.order_line + if line.product_id in raw_materials + ) + record.hide_action_purchase_orders = total_purchase_quantity < record.product_uom_qty and pr_ids.state != 'done' + + @api.depends('sale_order_id.mrp_production_ids.picking_ids', 'sale_order_id.mrp_production_ids.picking_ids.state') + def _compute_hide_action_stock_picking(self): + for record in self: + manufacturing_orders = record.sale_order_id.mrp_production_ids + record.hide_action_stock_picking = bool(manufacturing_orders.mapped('picking_ids').filtered( + lambda p: p.state == 'assigned')) + + def action_open_sale_order(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'res_model': 'sale.order', + 'res_id': self.sale_order_id.id, + 'view_mode': 'form', + } + def action_open_mrp_production(self): + self.ensure_one() mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered( lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == self.product_id.id ).ids @@ -364,3 +406,39 @@ class sf_production_plan(models.Model): 'view_mode': 'tree,form', }) return action + + def action_view_purchase_request(self): + self.ensure_one() + first_mp = self.env['mrp.production'].search( + [('origin', '=', self.sale_order_id.name)], limit=1, order='id asc') + pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_mp.name)]) + 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_stock_picking(self): + self.ensure_one() + action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all") + picking_ids = self.sale_order_id.mrp_production_ids.mapped('picking_ids').filtered( + lambda p: p.state == 'assigned') + if len(picking_ids) > 1: + action['domain'] = [('id', 'in', picking_ids.ids)] + elif picking_ids: + action['res_id'] = picking_ids.id + action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')] + if 'views' in action: + action['views'] += [(state, view) for state, view in action['views'] if view != 'form'] + return action diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index e3ca71ea..11736148 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -9,6 +9,7 @@ class="btn-primary"/> + @@ -40,10 +41,16 @@ + +