diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 2cc93f0a..50a9d732 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -230,33 +230,26 @@ class SfProductionDemandPlan(models.Model): else: line.model_long = None - @api.depends('sale_order_id.mrp_production_ids.workorder_ids.date_start') + @api.depends('mrp_production_ids.workorder_ids.date_start') def _compute_actual_start_date(self): for record in self: - if record.sale_order_id and record.sale_order_id.mrp_production_ids: - manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered( - lambda mo: mo.product_id == record.product_id) - if manufacturing_orders: - start_dates = [ - workorder.date_start for mo in manufacturing_orders - for workorder in mo.workorder_ids if workorder.date_start - ] - record.actual_start_date = min(start_dates) if start_dates else None - else: - record.actual_start_date = None + if record.mrp_production_ids: + start_dates = [ + workorder.date_start for mo in record.mrp_production_ids + for workorder in mo.workorder_ids if workorder.date_start + ] + record.actual_start_date = min(start_dates) if start_dates else None else: record.actual_start_date = None - @api.depends('sale_order_id.mrp_production_ids.workorder_ids.state', - 'sale_order_id.mrp_production_ids.workorder_ids.date_finished') + @api.depends('mrp_production_ids.workorder_ids.state', + 'mrp_production_ids.workorder_ids.date_finished') def _compute_actual_end_date(self): for record in self: - if record.sale_order_id and record.sale_order_id.mrp_production_ids: - 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 record.mrp_production_ids: + finished_orders = record.mrp_production_ids.filtered(lambda mo: mo.state == 'done') sum_product_qty = sum(finished_orders.mapped('product_qty')) - if finished_orders and float_compare(sum_product_qty, record.product_uom_qty, + if finished_orders and float_compare(sum_product_qty, record.plan_uom_qty, precision_rounding=record.product_id.uom_id.rounding) >= 0: end_dates = [ workorder.date_finished for mo in finished_orders @@ -268,27 +261,17 @@ class SfProductionDemandPlan(models.Model): else: record.actual_end_date = None - @api.depends('sale_order_id.mrp_production_ids.move_raw_ids.reserved_availability') + @api.depends('mrp_production_ids.move_raw_ids.reserved_availability') def _compute_material_check(self): for record in self: - if record.sale_order_id and record.sale_order_id.mrp_production_ids: - manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered( - lambda mo: mo.product_id == record.product_id) - - if manufacturing_orders and manufacturing_orders.move_raw_ids: - # 获取完成的制造订单 - done_manufacturing = manufacturing_orders.filtered(lambda mo: mo.state == 'done') - product_qty = sum(done_manufacturing.mapped('product_qty')) - # 需求数量-完成数量 - product_uom_qty = record.product_uom_qty - product_qty - total_reserved_availability = sum(manufacturing_orders.mapped('move_raw_ids.reserved_availability')) - if float_compare(total_reserved_availability, product_uom_qty, - precision_rounding=record.product_id.uom_id.rounding) >= 0: - record.material_check = '1' # 已齐套 - else: - record.material_check = '0' # 未齐套 + if record.mrp_production_ids and record.mrp_production_ids.move_raw_ids: + total_reserved_availability = sum( + record.mrp_production_ids.mapped('move_raw_ids.reserved_availability')) + if float_compare(total_reserved_availability, record.plan_uom_qty, + precision_rounding=record.product_id.uom_id.rounding) >= 0: + record.material_check = '1' # 已齐套 else: - record.material_check = None + record.material_check = '0' # 未齐套 else: record.material_check = None