pricing: add accounting code template field in Pricing (#89025)

This commit is contained in:
Lauréline Guérin 2024-04-09 13:04:56 +02:00 committed by Lauréline Guérin
parent 4442785d18
commit cfc2ff7b70
7 changed files with 46 additions and 0 deletions

View File

@ -123,6 +123,7 @@ class PricingForm(NewPricingForm):
'kind',
'reduction_rate',
'effort_rate_target',
'accounting_code',
]
widgets = {
'date_start': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
@ -143,6 +144,7 @@ class PricingForm(NewPricingForm):
'size': 100,
}
),
'accounting_code': forms.TextInput(attrs={'size': 100}),
}
def clean_slug(self):

View File

@ -0,0 +1,15 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pricing', '0001_squashed_0019_merge_models'),
]
operations = [
migrations.AddField(
model_name='pricing',
name='accounting_code',
field=models.CharField(blank=True, max_length=250, verbose_name='Accounting code (template)'),
),
]

View File

@ -310,6 +310,11 @@ class Pricing(WithApplicationMixin, models.Model):
max_pricing = models.DecimalField(
_('Maximal pricing'), max_digits=9, decimal_places=2, blank=True, null=True
)
accounting_code = models.CharField(
_('Accounting code (template)'),
max_length=250,
blank=True,
)
pricing_data = models.JSONField(null=True)
@ -338,6 +343,7 @@ class Pricing(WithApplicationMixin, models.Model):
yield from get_wcs_dependencies_from_template(self.reduction_rate)
if self.kind == 'effort':
yield from get_wcs_dependencies_from_template(self.effort_rate_target)
yield from get_wcs_dependencies_from_template(self.accounting_code)
def export_json(self):
return {
@ -351,6 +357,7 @@ class Pricing(WithApplicationMixin, models.Model):
'kind': self.kind,
'reduction_rate': self.reduction_rate,
'effort_rate_target': self.effort_rate_target,
'accounting_code': self.accounting_code,
'min_pricing': self.min_pricing,
'max_pricing': self.max_pricing,
'pricing_data': self.pricing_data,

View File

@ -59,6 +59,7 @@
{% elif object.kind == 'effort' %}
<li>{% trans "Pricing to be multiplied by the effort rate (template):" %} <pre>{{ object.effort_rate_target }}</pre></li>
{% endif %}
<li>{% trans "Accounting code (template):" %} <pre>{{ object.accounting_code }}</pre></li>
</ul>
</div>

View File

@ -307,6 +307,7 @@ def test_pricing_dependencies(mock_send, app, admin_user):
pricing.extra_variables = {}
pricing.reduction_rate = '{{ cards|objects:"card_model_1" }}'
pricing.effort_rate_target = '{{ cards|objects:"card_model_2:custom-view" }}'
pricing.accounting_code = '{{ cards|objects:"card_model_3" }}'
pricing.save()
resp = app.get('/api/export-import/pricings/foo-bar-pricing/dependencies/')
assert {
@ -329,6 +330,16 @@ def test_pricing_dependencies(mock_send, app, admin_user):
'redirect': 'http://wcs.example.org/api/export-import/cards/card_model_2/redirect/',
},
} not in resp.json['data']
assert {
'type': 'cards',
'id': 'card_model_3',
'text': 'Card Model 3',
'urls': {
'export': 'http://wcs.example.org/api/export-import/cards/card_model_3/',
'dependencies': 'http://wcs.example.org/api/export-import/cards/card_model_3/dependencies/',
'redirect': 'http://wcs.example.org/api/export-import/cards/card_model_3/redirect/',
},
} in resp.json['data']
pricing.kind = 'reduction'
pricing.save()

View File

@ -98,9 +98,11 @@ def test_edit_pricing(app, admin_user):
assert pricing.kind == 'basic'
assert pricing.reduction_rate == ''
assert pricing.effort_rate_target == ''
assert pricing.accounting_code == ''
resp = app.get('/manage/pricing/%s/edit/' % pricing.pk)
resp.form['kind'] = 'reduction'
resp.form['accounting_code'] = '424242'
resp = resp.form.submit()
assert resp.context['form'].errors['reduction_rate'] == [
'Declare the reduction rate you want to apply for this pricing.'
@ -115,6 +117,7 @@ def test_edit_pricing(app, admin_user):
assert pricing.kind == 'reduction'
assert pricing.reduction_rate == 'foo'
assert pricing.effort_rate_target == ''
assert pricing.accounting_code == '424242'
resp = app.get('/manage/pricing/%s/edit/' % pricing.pk)
resp.form['kind'] = 'effort'
@ -129,6 +132,7 @@ def test_edit_pricing(app, admin_user):
assert pricing.kind == 'effort'
assert pricing.reduction_rate == ''
assert pricing.effort_rate_target == 'foo'
assert pricing.accounting_code == '424242'
agenda = Agenda.objects.create(label='Foo bar')
pricing.agendas.add(agenda)

View File

@ -43,6 +43,7 @@ def test_import_export_pricing(app):
kind='reduction',
reduction_rate='foo',
effort_rate_target='bar',
accounting_code='foo',
min_pricing=35,
max_pricing=42,
pricing_data={
@ -54,6 +55,7 @@ def test_import_export_pricing(app):
data = export_site()
json_dump(data, io.StringIO()) # no error
Pricing.objects.all().delete()
Agenda.objects.all().delete()
with pytest.raises(LingoImportError) as excinfo:
import_site(data)
@ -77,6 +79,7 @@ def test_import_export_pricing(app):
assert pricing.kind == 'reduction'
assert pricing.reduction_rate == 'foo'
assert pricing.effort_rate_target == 'bar'
assert pricing.accounting_code == 'foo'
assert pricing.min_pricing == 35
assert pricing.max_pricing == 42
@ -85,6 +88,7 @@ def test_import_export_pricing(app):
pricing = Pricing.objects.get(pk=pricing.pk)
assert list(pricing.agendas.all()) == [agenda]
Pricing.objects.all().delete()
data['pricings'].append(
{
'slug': 'baz',
@ -98,6 +102,7 @@ def test_import_export_pricing(app):
'kind': 'effort',
'reduction_rate': 'foo2',
'effort_rate_target': 'bar2',
'accounting_code': 'foo2',
'min_pricing': 36,
'max_pricing': 43,
'pricing_data': {'foo': 'bar'},
@ -116,6 +121,7 @@ def test_import_export_pricing(app):
assert pricing.kind == 'effort'
assert pricing.reduction_rate == 'foo2'
assert pricing.effort_rate_target == 'bar2'
assert pricing.accounting_code == 'foo2'
assert pricing.min_pricing == 36
assert pricing.max_pricing == 43