From b2eddf55d2ff18a122fa301d2bc2df8a819dcea9 Mon Sep 17 00:00:00 2001 From: "Sigma Dimensions (Yass)" <79010126+myoualid@users.noreply.github.com> Date: Sat, 12 Aug 2023 12:58:16 +0100 Subject: [PATCH] Fix contracting/expanding cost schedule tree and add tests to avoid proof changes --- .../blenderbim/bim/module/cost/__init__.py | 83 ++++++++++--------- .../blenderbim/bim/module/cost/operator.py | 11 +++ .../blenderbim/bim/module/cost/ui.py | 4 +- src/blenderbim/blenderbim/tool/cost.py | 4 +- src/blenderbim/test/bim/feature/cost.feature | 48 +++++++++++ 5 files changed, 105 insertions(+), 45 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/cost/__init__.py b/src/blenderbim/blenderbim/bim/module/cost/__init__.py index 8a9ef49798..d279ad317c 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cost/__init__.py @@ -20,64 +20,65 @@ import bpy from . import ui, prop, operator classes = ( + operator.AddCostColumn, + operator.AddCostItem, + operator.AddCostItemQuantity, operator.AddCostSchedule, - operator.RemoveCostSchedule, - operator.EditCostSchedule, + operator.AddCostValue, + operator.AddCurrency, + operator.AddSummaryCostItem, + operator.AssignCostItemQuantity, + operator.AssignCostItemType, + operator.AssignCostValue, + operator.CalculateCostItemResourceValue, + operator.ChangeParentCostItem, + operator.ClearCostItemAssignments, + operator.ContractCostItem, + operator.ContractCostItemRate, + operator.ContractCostItems, + operator.CopyCostItem, + operator.CopyCostItemValues, + operator.DisableEditingCostItem, + operator.DisableEditingCostItemQuantity, + operator.DisableEditingCostItemValue, + operator.DisableEditingCostSchedule, operator.EditCostItem, operator.EditCostItemQuantity, operator.EditCostItemValue, operator.EditCostItemValueFormula, - operator.EnableEditingCostSchedule, - operator.EnableEditingCostItems, + operator.EditCostSchedule, operator.EnableEditingCostItem, - operator.ExportCostSchedules, - operator.ExpandCostItems, operator.EnableEditingCostItemQuantities, operator.EnableEditingCostItemQuantity, - operator.EnableEditingCostItemValues, + operator.EnableEditingCostItems, operator.EnableEditingCostItemValue, operator.EnableEditingCostItemValueFormula, - operator.DisableEditingCostItem, - operator.DisableEditingCostSchedule, - operator.DisableEditingCostItemQuantity, - operator.DisableEditingCostItemValue, - operator.AddCostColumn, - operator.RemoveCostColumn, - operator.AddCostItem, - operator.AddSummaryCostItem, + operator.EnableEditingCostItemValues, + operator.EnableEditingCostSchedule, operator.ExpandCostItem, - operator.ContractCostItem, + operator.ExpandCostItemRate, + operator.ExpandCostItems, + operator.ExportCostSchedules, + operator.HighlightProductCostItem, + operator.ImportCostScheduleCsv, + operator.LoadCostItemElementQuantities, + operator.LoadCostItemQuantities, + operator.LoadCostItemResourceQuantities, + operator.LoadCostItemTaskQuantities, + operator.LoadCostItemTypes, + operator.LoadProductCostItems, + operator.LoadScheduleOfRates, + operator.RemoveCostColumn, operator.RemoveCostItem, - operator.AssignCostItemType, - operator.UnassignCostItemType, - operator.AssignCostItemQuantity, - operator.UnassignCostItemQuantity, - operator.AddCostItemQuantity, operator.RemoveCostItemQuantity, - operator.AddCostValue, operator.RemoveCostItemValue, - operator.CopyCostItemValues, + operator.RemoveCostSchedule, + operator.ReorderCostItem, operator.SelectCostItemProducts, operator.SelectCostScheduleProducts, - operator.ImportCostScheduleCsv, - operator.LoadCostItemQuantities, - operator.LoadCostItemTypes, - operator.AssignCostValue, - operator.LoadScheduleOfRates, - operator.ExpandCostItemRate, - operator.ContractCostItemRate, - operator.CalculateCostItemResourceValue, - operator.ClearCostItemAssignments, - operator.HighlightProductCostItem, - operator.LoadProductCostItems, - operator.ReorderCostItem, operator.SelectUnassignedProducts, - operator.LoadCostItemElementQuantities, - operator.LoadCostItemTaskQuantities, - operator.LoadCostItemResourceQuantities, - operator.ChangeParentCostItem, - operator.CopyCostItem, - operator.AddCurrency, + operator.UnassignCostItemQuantity, + operator.UnassignCostItemType, prop.CostItem, prop.CostItemQuantity, prop.CostItemType, diff --git a/src/blenderbim/blenderbim/bim/module/cost/operator.py b/src/blenderbim/blenderbim/bim/module/cost/operator.py index 02c7b2e9a8..91bf921347 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cost/operator.py @@ -156,6 +156,17 @@ class ContractCostItem(bpy.types.Operator, tool.Ifc.Operator): core.contract_cost_item(tool.Cost, cost_item=tool.Ifc.get().by_id(self.cost_item)) +class ContractCostItems(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.contract_cost_items" + bl_label = "Contract Cost Item" + bl_options = {"REGISTER", "UNDO"} + bl_description = "Collapse cost item tree" + cost_item: bpy.props.IntProperty() + + def _execute(self, context): + core.contract_cost_items(tool.Cost) + + class RemoveCostItem(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_cost_item" bl_label = "Remove Cost Item" diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py index 832e69c871..3c5b6e49a5 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -139,8 +139,8 @@ class BIM_PT_cost_schedules(Panel): row = self.layout.row(align=True) row.alignment = "RIGHT" row.operator("bim.add_summary_cost_item", text="Add Summary Cost", icon="ADD") - row.operator("bim.expand_all_tasks", text="Expand All") - row.operator("bim.contract_all_tasks", text="Contract All") + row.operator("bim.expand_cost_items", text="Expand All") + row.operator("bim.contract_cost_items", text="Contract All") row = self.layout.row(align=True) row.alignment = "RIGHT" if self.props.cost_items and self.props.active_cost_item_index < len(self.props.cost_items): diff --git a/src/blenderbim/blenderbim/tool/cost.py b/src/blenderbim/blenderbim/tool/cost.py index f6c83b051c..698625bc33 100644 --- a/src/blenderbim/blenderbim/tool/cost.py +++ b/src/blenderbim/blenderbim/tool/cost.py @@ -96,11 +96,11 @@ class Cost(blenderbim.core.tool.Cost): props.contracted_cost_items = json.dumps(cls.contracted_cost_items) @classmethod - def contract_cost_item(cls, cost_item_id): + def contract_cost_item(cls, cost_item): props = bpy.context.scene.BIMCostProperties if not hasattr(cls, "contracted_cost_items"): cls.contracted_cost_items = json.loads(props.contracted_cost_items) - cls.contracted_cost_items.append(cost_item_id) + cls.contracted_cost_items.append(cost_item.id()) props.contracted_cost_items = json.dumps(cls.contracted_cost_items) @classmethod diff --git a/src/blenderbim/test/bim/feature/cost.feature b/src/blenderbim/test/bim/feature/cost.feature index 1098c96716..aefe3e5ff9 100644 --- a/src/blenderbim/test/bim/feature/cost.feature +++ b/src/blenderbim/test/bim/feature/cost.feature @@ -3,6 +3,7 @@ Feature: Cost Scenario: Add cost schedule Given an empty IFC project + And I set "scene.BIMCostProperties.cost_schedule_predefined_types" to "COSTPLAN" When I press "bim.add_cost_schedule" Then nothing happens @@ -111,6 +112,53 @@ Scenario: Add cost item When I press "bim.add_cost_item(cost_item={cost_item})" Then nothing happens +Scenario: Contract Cost Item + Given an empty IFC project + And I set "scene.BIMCostProperties.cost_schedule_predefined_types" to "COSTPLAN" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item()" + And I press "bim.add_cost_item(cost_item={cost_item})" + When I press "bim.contract_cost_item(cost_item={cost_item})" + Then nothing happens + +Scenario: Contract All Cost Items + Given an empty IFC project + And I set "scene.BIMCostProperties.cost_schedule_predefined_types" to "COSTPLAN" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item()" + And I press "bim.add_cost_item(cost_item={cost_item})" + When I press "bim.contract_cost_items" + Then nothing happens + +Scenario: Expand Cost Item + Given an empty IFC project + And I set "scene.BIMCostProperties.cost_schedule_predefined_types" to "COSTPLAN" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item()" + And I press "bim.add_cost_item(cost_item={cost_item})" + And I press "bim.contract_cost_item(cost_item={cost_item})" + When I press "bim.expand_cost_item(cost_item={cost_item})" + Then nothing happens + + +Scenario: Expand All Cost Items + Given an empty IFC project + And I set "scene.BIMCostProperties.cost_schedule_predefined_types" to "COSTPLAN" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item()" + And I press "bim.add_cost_item(cost_item={cost_item})" + When I press "bim.expand_cost_items" + Then nothing happens + + Scenario: Enable editing cost item quantities Given an empty IFC project And I press "bim.add_cost_schedule"