mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 20:00:02 +00:00
Fix bug where calendar caching meant invalid duration calculations if you edited your calendar after a date calculation.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.date
|
import ifcopenshell.util.date
|
||||||
|
import ifcopenshell.util.sequence
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
@@ -93,4 +94,8 @@ class Usecase:
|
|||||||
time_periods = list(self.settings["recurrence_pattern"].TimePeriods or [])
|
time_periods = list(self.settings["recurrence_pattern"].TimePeriods or [])
|
||||||
time_periods.append(time_period)
|
time_periods.append(time_period)
|
||||||
self.settings["recurrence_pattern"].TimePeriods = time_periods
|
self.settings["recurrence_pattern"].TimePeriods = time_periods
|
||||||
|
|
||||||
|
ifcopenshell.util.sequence.is_working_day.cache_clear()
|
||||||
|
ifcopenshell.util.sequence.is_calendar_applicable.cache_clear()
|
||||||
|
|
||||||
return time_period
|
return time_period
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.util.sequence
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, recurrence_pattern=None, attributes=None):
|
def __init__(self, file, recurrence_pattern=None, attributes=None):
|
||||||
@@ -56,3 +59,6 @@ class Usecase:
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
for name, value in self.settings["attributes"].items():
|
for name, value in self.settings["attributes"].items():
|
||||||
setattr(self.settings["recurrence_pattern"], name, value)
|
setattr(self.settings["recurrence_pattern"], name, value)
|
||||||
|
|
||||||
|
ifcopenshell.util.sequence.is_working_day.cache_clear()
|
||||||
|
ifcopenshell.util.sequence.is_calendar_applicable.cache_clear()
|
||||||
|
|||||||
@@ -44,10 +44,11 @@ class Usecase:
|
|||||||
work_time = ifcopenshell.api.run("sequence.add_work_time", model,
|
work_time = ifcopenshell.api.run("sequence.add_work_time", model,
|
||||||
work_calendar=calendar, time_type="WorkingTimes")
|
work_calendar=calendar, time_type="WorkingTimes")
|
||||||
|
|
||||||
# Edit our work time to state that the work time only applies after
|
# If we don't specify any recurring time periods in our work time,
|
||||||
# a start date.
|
# we need to specify a start and end date of the work time. It
|
||||||
|
# starts at 0:00 on the start date and 24:00 at the end date.
|
||||||
ifcopenshell.api.run("sequence.edit_work_time", model,
|
ifcopenshell.api.run("sequence.edit_work_time", model,
|
||||||
work_time=work_time, attributes={"StartDate": "2000-01-01"})
|
work_time=work_time, attributes={"StartDate": "2000-01-01", "FinishDate": "2000-01-02"})
|
||||||
"""
|
"""
|
||||||
self.file = file
|
self.file = file
|
||||||
self.settings = {"work_time": work_time, "attributes": attributes or {}}
|
self.settings = {"work_time": work_time, "attributes": attributes or {}}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ def is_calendar_applicable(day, calendar):
|
|||||||
|
|
||||||
|
|
||||||
def is_day_in_work_time(day, work_time):
|
def is_day_in_work_time(day, work_time):
|
||||||
is_day_in_work_time = False
|
is_day_in_work_time = True
|
||||||
if isinstance(day, datetime.datetime):
|
if isinstance(day, datetime.datetime):
|
||||||
day = datetime.date(day.year, day.month, day.day)
|
day = datetime.date(day.year, day.month, day.day)
|
||||||
if work_time.Start:
|
if work_time.Start:
|
||||||
|
|||||||
@@ -193,3 +193,52 @@ class TestEditTaskTime(test.bootstrap.IFC4):
|
|||||||
assert task_time.ScheduleDuration == "P0D"
|
assert task_time.ScheduleDuration == "P0D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T09:00:00"
|
assert task_time.ScheduleStart == "2000-01-01T09:00:00"
|
||||||
assert task_time.ScheduleFinish == "2000-01-01T09:00:00"
|
assert task_time.ScheduleFinish == "2000-01-01T09:00:00"
|
||||||
|
|
||||||
|
def test_editing_a_start_date_and_duration_with_a_calendar(self):
|
||||||
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
calendar = ifcopenshell.api.run("sequence.add_work_calendar", self.file)
|
||||||
|
task = self.file.createIfcTask()
|
||||||
|
ifcopenshell.api.run("control.assign_control", self.file, relating_control=calendar, related_object=task)
|
||||||
|
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=task)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"sequence.edit_task_time",
|
||||||
|
self.file,
|
||||||
|
task_time=task_time,
|
||||||
|
attributes={
|
||||||
|
"DurationType": "WORKTIME",
|
||||||
|
"ScheduleDuration": "P7D",
|
||||||
|
"ScheduleStart": datetime.datetime(2020, 1, 1),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert task_time.ScheduleStart == "2020-01-01T09:00:00"
|
||||||
|
assert task_time.ScheduleFinish == "2020-01-07T17:00:00"
|
||||||
|
assert task_time.ScheduleDuration == "P7D"
|
||||||
|
|
||||||
|
work_time = ifcopenshell.api.run(
|
||||||
|
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="WorkingTimes"
|
||||||
|
)
|
||||||
|
pattern = ifcopenshell.api.run(
|
||||||
|
"sequence.assign_recurrence_pattern", self.file, parent=work_time, recurrence_type="WEEKLY"
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"sequence.edit_recurrence_pattern",
|
||||||
|
self.file,
|
||||||
|
recurrence_pattern=pattern,
|
||||||
|
attributes={"WeekdayComponent": [1, 2, 3, 4, 5]},
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"sequence.add_time_period", self.file, recurrence_pattern=pattern, start_time="09:00", end_time="17:00"
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"sequence.edit_task_time",
|
||||||
|
self.file,
|
||||||
|
task_time=task_time,
|
||||||
|
attributes={
|
||||||
|
"DurationType": "WORKTIME",
|
||||||
|
"ScheduleDuration": "P7D",
|
||||||
|
"ScheduleStart": datetime.datetime(2020, 1, 1),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert task_time.ScheduleStart == "2020-01-01T09:00:00"
|
||||||
|
assert task_time.ScheduleFinish == "2020-01-09T17:00:00"
|
||||||
|
assert task_time.ScheduleDuration == "P7D"
|
||||||
|
|||||||
Reference in New Issue
Block a user