agendas: do not import exception from settings when duplicating (#47916)
This commit is contained in:
parent
f880490e00
commit
bb3e011bea
|
@ -1132,13 +1132,13 @@ class Desk(models.Model):
|
|||
ordering = ['label']
|
||||
unique_together = ['agenda', 'slug']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
def save(self, *args, import_exceptions=True, **kwargs):
|
||||
assert self.agenda.kind != 'virtual', "a desk can't reference a virtual agenda"
|
||||
first_created = not self.pk
|
||||
if not self.slug:
|
||||
self.slug = generate_slug(self, agenda=self.agenda)
|
||||
super(Desk, self).save(*args, **kwargs)
|
||||
if first_created:
|
||||
if first_created and import_exceptions:
|
||||
self.import_timeperiod_exceptions_from_settings(enable=True)
|
||||
|
||||
@property
|
||||
|
@ -1179,7 +1179,7 @@ class Desk(models.Model):
|
|||
if agenda_target:
|
||||
new_desk.agenda = agenda_target
|
||||
# store new desk
|
||||
new_desk.save()
|
||||
new_desk.save(import_exceptions=False)
|
||||
|
||||
# clone related objects
|
||||
for time_period in self.timeperiod_set.all():
|
||||
|
|
|
@ -991,6 +991,29 @@ def test_desk_duplicate_exception_sources():
|
|||
assert not new_desk.timeperiodexception_set.exists()
|
||||
|
||||
|
||||
@override_settings(
|
||||
EXCEPTIONS_SOURCES={'holidays': {'class': 'workalendar.europe.France', 'label': 'Holidays'},}
|
||||
)
|
||||
def test_desk_duplicate_exception_source_from_settings():
|
||||
agenda = Agenda.objects.create(label='Agenda')
|
||||
desk = Desk.objects.create(label='Desk', agenda=agenda)
|
||||
|
||||
source = desk.timeperiodexceptionsource_set.get(settings_slug='holidays')
|
||||
assert source.enabled
|
||||
exceptions_count = desk.timeperiodexception_set.count()
|
||||
|
||||
new_desk = desk.duplicate(label="New Desk")
|
||||
assert new_desk.timeperiodexceptionsource_set.filter(settings_slug='holidays').count() == 1
|
||||
assert new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled
|
||||
assert new_desk.timeperiodexception_set.count() == exceptions_count
|
||||
|
||||
source.disable()
|
||||
|
||||
new_desk = desk.duplicate(label="New Desk")
|
||||
assert not new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled
|
||||
assert not new_desk.timeperiodexception_set.exists()
|
||||
|
||||
|
||||
def test_agenda_meetings_duplicate():
|
||||
group = Group(name=u'Group')
|
||||
group.save()
|
||||
|
|
Loading…
Reference in New Issue