From 9123aeaee8b03679adff1f10114fe6dc9408bf9a Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 16 Jun 2025 14:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E7=BA=BF=E4=B8=8B=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E5=AE=8C=E5=B7=A5=E5=90=8E=E6=9C=AA=E8=AE=B0=E5=BD=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=AE=8C=E5=B7=A5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/sf_production_demand_plan.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index d484fb8e..ef11adcc 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -259,7 +259,9 @@ class SfProductionDemandPlan(models.Model): manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered( lambda mo: mo.product_id == record.product_id) finished_orders = manufacturing_orders.filtered(lambda mo: mo.state == 'done') - if len(finished_orders) >= record.product_uom_qty: + sum_product_qty = sum(finished_orders.mapped('product_qty')) + if finished_orders and float_compare(sum_product_qty, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) >= 0: end_dates = [ workorder.date_finished for mo in finished_orders for workorder in mo.workorder_ids if workorder.date_finished @@ -361,7 +363,8 @@ class SfProductionDemandPlan(models.Model): ) for order in purchase_orders ) - if total_purchase_quantity < record.product_uom_qty: + if float_compare(total_purchase_quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: pr_ids = self.env['purchase.request'].sudo().search( [('line_ids.product_id', 'in', raw_materials.ids), ('state', '!=', 'done')]) outsourcing_purchase_request.extend(pr_ids.ids) @@ -378,7 +381,9 @@ class SfProductionDemandPlan(models.Model): ) for order in purchase_orders ) - if total_purchase_quantity < record.product_uom_qty: + + if float_compare(total_purchase_quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: pr_ids = self.env['purchase.request'].sudo().search( [('origin', 'like', record.sale_order_id.name), ('state', '!=', 'done')]) outsourcing_purchase_request.extend(pr_ids.ids) @@ -400,7 +405,9 @@ class SfProductionDemandPlan(models.Model): ) for order in product_purchase_orders ) - if total_outsourcing_purchase_quantity / total_product_qty < record.product_uom_qty: + quantity = total_outsourcing_purchase_quantity / total_product_qty + if float_compare(quantity, record.product_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) == -1: purchase_request = self.env['purchase.request'].sudo().search( [('line_ids.product_id', 'in', bom_product_ids.ids), ('line_ids.purchase_state', 'not in', ('purchase', 'done')), ('state', '!=', 'done')])