from dataclasses import dataclass @dataclass class CheckboxState: checked: bool = False visible: bool = True enabled: bool = True @dataclass class SelectState: value: str = None visible: bool = True enabled: bool = True @dataclass class RouteModuleState: enabled: CheckboxState smart_routing: CheckboxState predictive_pickup: CheckboxState automatic_planning: CheckboxState geo_routing: CheckboxState packing_model: SelectState prekitting_to_box: CheckboxState prekitting_to_pallet: CheckboxState real_time_stock: CheckboxState warehouse: CheckboxState end_warehouse_tracking: CheckboxState custom_forms_in_routing: CheckboxState @staticmethod def from_form(values: dict[str, str]) -> "RouteModuleState": return RouteModuleState( enabled=CheckboxState(checked=values.get("route_module") == "on"), smart_routing=CheckboxState(checked=values.get("smart_routing") == "on"), predictive_pickup=CheckboxState( checked=values.get("predictive_pickup") == "on" ), automatic_planning=CheckboxState( checked=values.get("automatic_planning") == "on" ), geo_routing=CheckboxState(checked=values.get("geo_routing") == "on"), packing_model=SelectState(value=values.get("packing_model")), prekitting_to_box=CheckboxState( checked=values.get("prekitting_to_box") == "on" ), prekitting_to_pallet=CheckboxState( checked=values.get("prekitting_to_pallet") == "on" ), real_time_stock=CheckboxState( checked=values.get("real_time_stock") == "on" ), warehouse=CheckboxState(checked=values.get("warehouse") == "on"), end_warehouse_tracking=CheckboxState( checked=values.get("end_warehouse_tracking") == "on" ), custom_forms_in_routing=CheckboxState( checked=values.get("custom_forms_in_routing") == "on" ), ) @dataclass class FormState: route_module: RouteModuleState