(self, cost_item: CostItem, parent: Optional[ifcopenshell.entity_instance] = None)
| 265 | self.create_cost_item(cost_item, parent) |
| 266 | |
| 267 | def create_cost_item(self, cost_item: CostItem, parent: Optional[ifcopenshell.entity_instance] = None) -> None: |
| 268 | assert self.file |
| 269 | if parent is None: |
| 270 | cost_item["ifc"] = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=self.cost_schedule) |
| 271 | else: |
| 272 | cost_item["ifc"] = ifcopenshell.api.cost.add_cost_item(self.file, cost_item=parent) |
| 273 | |
| 274 | cost_item["ifc"].Name = cost_item["Name"] |
| 275 | cost_item["ifc"].Description = cost_item["Description"] |
| 276 | cost_item["ifc"].Identification = cost_item["Identification"] |
| 277 | |
| 278 | cost_values = cost_item["CostValues"] |
| 279 | if ((isinstance(cost_values, dict) and len(cost_values) == 0) or (cost_values is None)) and cost_item[ |
| 280 | "children" |
| 281 | ]: |
| 282 | if not self.is_schedule_of_rates: |
| 283 | cost_value = ifcopenshell.api.cost.add_cost_value(self.file, parent=cost_item["ifc"]) |
| 284 | cost_value.Category = "*" |
| 285 | elif self.has_categories: |
| 286 | assert isinstance(cost_values, dict) |
| 287 | for category, value in cost_values.items(): |
| 288 | cost_value = ifcopenshell.api.cost.add_cost_value(self.file, parent=cost_item["ifc"]) |
| 289 | cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(value) |
| 290 | if category != "Rate" or category != "Price": |
| 291 | if "Rate" in category or "Price" in category: |
| 292 | category = category.replace("Rate", "") |
| 293 | category = category.strip() |
| 294 | cost_value.Category = category |
| 295 | elif cost_values: |
| 296 | cost_value = ifcopenshell.api.cost.add_cost_value(self.file, parent=cost_item["ifc"]) |
| 297 | cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(cost_item["CostValues"]) |
| 298 | if self.is_schedule_of_rates: |
| 299 | measure_class = ifcopenshell.util.unit.get_symbol_measure_class(cost_item["Unit"]) |
| 300 | value_component = self.file.create_entity(measure_class, cost_item["Quantity"]) |
| 301 | unit_component = None |
| 302 | |
| 303 | if measure_class == "IfcNumericMeasure": |
| 304 | unit_component = self.create_unit(cost_item["Unit"]) |
| 305 | else: |
| 306 | unit_type = ifcopenshell.util.unit.get_measure_unit_type(measure_class) |
| 307 | unit_assignment = ifcopenshell.util.unit.get_unit_assignment(self.file) |
| 308 | if unit_assignment: |
| 309 | units = [u for u in unit_assignment.Units if getattr(u, "UnitType", None) == unit_type] |
| 310 | if units: |
| 311 | unit_component = units[0] |
| 312 | if not unit_component: |
| 313 | unit_component = self.create_unit(cost_item["Unit"]) |
| 314 | |
| 315 | cost_value.UnitBasis = self.file.createIfcMeasureWithUnit(value_component, unit_component) |
| 316 | |
| 317 | if self.has_rates: |
| 318 | cost_rate = cost_item["CostRate"] |
| 319 | assert isinstance(cost_rate, dict) |
| 320 | |
| 321 | if cost_rate.get("Schedule") and cost_rate.get("RateID"): |
| 322 | # if cost_rate["Schedule"] is not "": |
| 323 | schedules = self.file.by_type("IfcCostSchedule") |
| 324 | for schedule in schedules: |
no test coverage detected