From 22ccb095ee2a1f1ec91a1e53d4589c056a11bb8a Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 7 Jul 2025 10:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AE=A1=E5=88=92=E4=B8=8B?= =?UTF-8?q?=E8=BE=BE=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/mrp_production.py | 19 ++++++++++++++++++- .../models/sf_production_demand_plan.py | 10 ++++++++++ sf_mrs_connect/controllers/controllers.py | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/sf_demand_plan/models/mrp_production.py b/sf_demand_plan/models/mrp_production.py index ebb87971..476bcbaa 100644 --- a/sf_demand_plan/models/mrp_production.py +++ b/sf_demand_plan/models/mrp_production.py @@ -22,5 +22,22 @@ class MrpProduction(models.Model): def _get_purchase_request(self): """获取跟制造订单相关的采购申请单(根据采购申请单行项目的产品匹配)""" - pr_ids = self.env['purchase.request'].sudo().search([('line_ids.demand_plan_line_id', 'in', self.demand_plan_line_id.ids)]) + pr_ids = self.env['purchase.request'].sudo().search( + [('line_ids.demand_plan_line_id', 'in', self.demand_plan_line_id.ids)]) return pr_ids + + @api.depends('procurement_group_id', 'procurement_group_id.stock_move_ids.group_id') + def _compute_picking_ids(self): + for order in self: + if order.product_id.product_tmpl_id.single_manufacturing == True and not order.is_remanufacture: + first_order = self.env['mrp.production'].search( + [('demand_plan_line_id', '=', order.demand_plan_line_id.id), ('product_id', '=', order.product_id.id)], limit=1, order='id asc') + order.picking_ids = self.env['stock.picking'].search([ + ('group_id', '=', first_order.procurement_group_id.id), ('group_id', '!=', False), + ]) + order.delivery_count = len(first_order.picking_ids) + else: + order.picking_ids = self.env['stock.picking'].search([ + ('group_id', '=', order.procurement_group_id.id), ('group_id', '!=', False), + ]) + order.delivery_count = len(order.picking_ids) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 50a9d732..0f8fe1e8 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -178,6 +178,16 @@ class SfProductionDemandPlan(models.Model): if line_ids: raise ValidationError(_("计划量不能小于等于0")) + @api.constrains('new_supply_method') + def _check_new_supply_method(self): + product_name = [] + for line in self: + if line.new_supply_method == 'purchase' and line.is_incoming_material: + product_name.append(line.product_id.display_name) + if product_name: + unique_product_names = list(set(product_name)) + raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names)) + @api.depends('new_supply_method') def _compute_custom_made_type(self): DemandPlan = self.env['sf.production.demand.plan'].sudo() diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index b06c4213..a6c1fa6c 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -44,7 +44,8 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController): if productions: # 修改需求计划中的程序工时 demand_plan = request.env['sf.production.demand.plan'].with_user( - request.env.ref("base.user_admin")).search([('model_id', '=', ret['folder_name'])]) + request.env.ref("base.user_admin")).search( + [('model_id', '=', ret['folder_name']), ('new_supply_method', '=', 'custom_made')]) if demand_plan and ret['total_estimated_time']: demand_plan.write( {'processing_time': ret['total_estimated_time']})