agendas: add pricing fields to CheckType model (#63810)
This commit is contained in:
parent
3a1655adff
commit
a2350a6e36
|
@ -18,4 +18,23 @@ class Migration(migrations.Migration):
|
|||
verbose_name='Kind',
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='checktype',
|
||||
name='pricing',
|
||||
field=models.DecimalField(
|
||||
blank=True,
|
||||
decimal_places=2,
|
||||
help_text='Fixed pricing',
|
||||
max_digits=5,
|
||||
null=True,
|
||||
verbose_name='Pricing',
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='checktype',
|
||||
name='pricing_rate',
|
||||
field=models.PositiveIntegerField(
|
||||
blank=True, help_text='Percentage rate', null=True, verbose_name='Pricing rate'
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -3095,6 +3095,12 @@ class CheckType(models.Model):
|
|||
choices=[('absence', _('Absence')), ('presence', _('Presence'))],
|
||||
default='absence',
|
||||
)
|
||||
pricing = models.DecimalField(
|
||||
_('Pricing'), max_digits=5, decimal_places=2, help_text=_('Fixed pricing'), blank=True, null=True
|
||||
)
|
||||
pricing_rate = models.PositiveIntegerField(
|
||||
_('Pricing rate'), help_text=_('Percentage rate'), blank=True, null=True
|
||||
)
|
||||
objects = CheckTypeManager()
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -69,10 +69,27 @@ from . import widgets
|
|||
from .widgets import SplitDateTimeField, WeekdaysWidget
|
||||
|
||||
|
||||
class CheckTypeForm(forms.ModelForm):
|
||||
class NewCheckTypeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CheckType
|
||||
fields = ['label', 'slug']
|
||||
fields = ['label', 'kind', 'pricing', 'pricing_rate']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not settings.CHRONO_ENABLE_PRICING:
|
||||
del self.fields['pricing']
|
||||
del self.fields['pricing_rate']
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.cleaned_data.get('pricing') and self.cleaned_data.get('pricing_rate'):
|
||||
raise ValidationError(_('Please choose between pricing and pricing rate.'))
|
||||
|
||||
|
||||
class CheckTypeForm(NewCheckTypeForm):
|
||||
class Meta:
|
||||
model = CheckType
|
||||
fields = ['label', 'slug', 'pricing', 'pricing_rate']
|
||||
|
||||
def clean_slug(self):
|
||||
slug = self.cleaned_data['slug']
|
||||
|
|
|
@ -114,6 +114,7 @@ from .forms import (
|
|||
EventsTimesheetForm,
|
||||
ImportEventsForm,
|
||||
MeetingTypeForm,
|
||||
NewCheckTypeForm,
|
||||
NewDeskForm,
|
||||
NewEventForm,
|
||||
NewMeetingTypeForm,
|
||||
|
@ -746,7 +747,7 @@ check_type_group_export = CheckTypeGroupExport.as_view()
|
|||
class CheckTypeAddView(CreateView):
|
||||
template_name = 'chrono/manager_check_type_form.html'
|
||||
model = CheckType
|
||||
fields = ['kind', 'label']
|
||||
form_class = NewCheckTypeForm
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.group_pk = kwargs.pop('group_pk')
|
||||
|
|
|
@ -184,6 +184,9 @@ except ImportError:
|
|||
WORKING_DAY_CALENDAR = None
|
||||
EXCEPTIONS_SOURCES = {}
|
||||
|
||||
# feature flag for publik-famille & pricing developements
|
||||
CHRONO_ENABLE_PRICING = False
|
||||
|
||||
TEMPLATE_VARS = {}
|
||||
SMS_URL = ''
|
||||
SMS_SENDER = ''
|
||||
|
|
|
@ -102,6 +102,8 @@ def test_add_check_type(app, admin_user):
|
|||
assert check_type.group == group
|
||||
assert check_type.slug == 'foo-reason'
|
||||
assert check_type.kind == 'absence'
|
||||
assert check_type.pricing is None
|
||||
assert check_type.pricing_rate is None
|
||||
|
||||
resp = app.get('/manage/check-type/group/%s/add/' % group.pk)
|
||||
resp.form['label'] = 'Foo reason'
|
||||
|
@ -114,6 +116,39 @@ def test_add_check_type(app, admin_user):
|
|||
assert check_type.kind == 'presence'
|
||||
|
||||
|
||||
def test_add_check_type_pricing(settings, app, admin_user):
|
||||
group = CheckTypeGroup.objects.create(label='Foo bar')
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/check-type/group/%s/add/' % group.pk)
|
||||
assert 'pricing' in resp.context['form'].fields
|
||||
assert 'pricing_rate' in resp.context['form'].fields
|
||||
resp.form['label'] = 'Foo reason'
|
||||
resp.form['pricing'] = 42
|
||||
resp.form['pricing_rate'] = 150
|
||||
resp = resp.form.submit()
|
||||
assert resp.context['form'].errors['__all__'] == ['Please choose between pricing and pricing rate.']
|
||||
resp.form['pricing'] = 42
|
||||
resp.form['pricing_rate'] = None
|
||||
resp = resp.form.submit()
|
||||
check_type = CheckType.objects.latest('pk')
|
||||
assert check_type.pricing == 42
|
||||
assert check_type.pricing_rate is None
|
||||
|
||||
resp = app.get('/manage/check-type/group/%s/add/' % group.pk)
|
||||
resp.form['label'] = 'Foo reason'
|
||||
resp.form['pricing_rate'] = 150
|
||||
resp = resp.form.submit()
|
||||
check_type = CheckType.objects.latest('pk')
|
||||
assert check_type.pricing is None
|
||||
assert check_type.pricing_rate == 150
|
||||
|
||||
settings.CHRONO_ENABLE_PRICING = False
|
||||
resp = app.get('/manage/check-type/group/%s/add/' % group.pk)
|
||||
assert 'pricing' not in resp.context['form'].fields
|
||||
assert 'pricing_rate' not in resp.context['form'].fields
|
||||
|
||||
|
||||
def test_add_check_type_as_manager(app, manager_user, agenda_with_restrictions):
|
||||
group = CheckTypeGroup.objects.create(label='Foo bar')
|
||||
|
||||
|
@ -144,6 +179,8 @@ def test_edit_check_type(app, admin_user):
|
|||
assert check_type.label == 'Foo bar reason'
|
||||
assert check_type.slug == 'foo-bar-reason'
|
||||
assert check_type.kind == 'presence'
|
||||
assert check_type.pricing is None
|
||||
assert check_type.pricing_rate is None
|
||||
|
||||
app.get('/manage/check-type/group/%s/%s/edit/' % (group2.pk, check_type.pk), status=404)
|
||||
|
||||
|
@ -156,6 +193,39 @@ def test_edit_check_type_as_manager(app, manager_user, agenda_with_restrictions)
|
|||
app.get('/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk), status=403)
|
||||
|
||||
|
||||
def test_edit_check_type_pricing(settings, app, admin_user):
|
||||
group = CheckTypeGroup.objects.create(label='Foo bar')
|
||||
check_type = CheckType.objects.create(label='Foo reason', group=group)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk))
|
||||
assert 'pricing' in resp.context['form'].fields
|
||||
assert 'pricing_rate' in resp.context['form'].fields
|
||||
resp.form['pricing'] = 42
|
||||
resp.form['pricing_rate'] = 150
|
||||
resp = resp.form.submit()
|
||||
assert resp.context['form'].errors['__all__'] == ['Please choose between pricing and pricing rate.']
|
||||
resp.form['pricing'] = 42
|
||||
resp.form['pricing_rate'] = None
|
||||
resp = resp.form.submit()
|
||||
check_type.refresh_from_db()
|
||||
assert check_type.pricing == 42
|
||||
assert check_type.pricing_rate is None
|
||||
|
||||
resp = app.get('/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk))
|
||||
resp.form['pricing'] = None
|
||||
resp.form['pricing_rate'] = 150
|
||||
resp = resp.form.submit()
|
||||
check_type.refresh_from_db()
|
||||
assert check_type.pricing is None
|
||||
assert check_type.pricing_rate == 150
|
||||
|
||||
settings.CHRONO_ENABLE_PRICING = False
|
||||
resp = app.get('/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk))
|
||||
assert 'pricing' not in resp.context['form'].fields
|
||||
assert 'pricing_rate' not in resp.context['form'].fields
|
||||
|
||||
|
||||
def test_delete_check_type(app, admin_user):
|
||||
group = CheckTypeGroup.objects.create(label='Foo bar')
|
||||
check_type = CheckType.objects.create(label='Foo reason', group=group)
|
||||
|
|
|
@ -32,3 +32,4 @@ KNOWN_SERVICES = {
|
|||
EXCEPTIONS_SOURCES = {}
|
||||
|
||||
SITE_BASE_URL = 'https://example.com'
|
||||
CHRONO_ENABLE_PRICING = True
|
||||
|
|
Loading…
Reference in New Issue