diff --git a/leasing/enums.py b/leasing/enums.py index 88032d00..d62f6cb0 100644 --- a/leasing/enums.py +++ b/leasing/enums.py @@ -659,16 +659,6 @@ class Labels: KUVA_NUP = "KuVa / Nuorisopalvelut" -def is_akv_or_kuva_service_unit_id(service_unit_id: int) -> bool: - akv_kuva_service_unit_ids = [ - ServiceUnitId.AKV, - ServiceUnitId.KUVA_LIPA, - ServiceUnitId.KUVA_UPA, - ServiceUnitId.KUVA_NUP, - ] - return service_unit_id in akv_kuva_service_unit_ids - - class SapSalesOfficeNumber(Enum): """ In Finnish: SAP myyntitoimiston numero diff --git a/leasing/fixtures/service_unit.json b/leasing/fixtures/service_unit.json index 179f978b..fad5fb2e 100644 --- a/leasing/fixtures/service_unit.json +++ b/leasing/fixtures/service_unit.json @@ -15,6 +15,7 @@ "first_contract_number": null, "default_receivable_type_rent": 1, "default_receivable_type_collateral": 8, + "use_rent_override_receivable_type": false, "created_at": "2021-11-22T08:00:00Z", "modified_at": "2021-11-22T08:00:00Z" } @@ -35,6 +36,7 @@ "first_contract_number": 100000, "default_receivable_type_rent": null, "default_receivable_type_collateral": null, + "use_rent_override_receivable_type": true, "created_at": "2023-09-04T12:00:00Z", "modified_at": "2023-09-04T12:00:00Z" } @@ -55,6 +57,7 @@ "first_contract_number": 200000, "default_receivable_type_rent": null, "default_receivable_type_collateral": null, + "use_rent_override_receivable_type": true, "created_at": "2023-09-04T12:00:00Z", "modified_at": "2023-09-04T12:00:00Z" } @@ -75,6 +78,7 @@ "first_contract_number": 200000, "default_receivable_type_rent": null, "default_receivable_type_collateral": null, + "use_rent_override_receivable_type": true, "created_at": "2023-09-04T12:00:00Z", "modified_at": "2023-09-04T12:00:00Z" } @@ -95,6 +99,7 @@ "first_contract_number": 200000, "default_receivable_type_rent": null, "default_receivable_type_collateral": null, + "use_rent_override_receivable_type": true, "created_at": "2023-09-04T12:00:00Z", "modified_at": "2023-09-04T12:00:00Z" } diff --git a/leasing/migrations/0081_serviceunit_use_rent_override_receivable_type.py b/leasing/migrations/0081_serviceunit_use_rent_override_receivable_type.py new file mode 100644 index 00000000..ee8732cf --- /dev/null +++ b/leasing/migrations/0081_serviceunit_use_rent_override_receivable_type.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.14 on 2024-11-20 11:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("leasing", "0080_alter_contact_options"), + ] + + operations = [ + migrations.AddField( + model_name="serviceunit", + name="use_rent_override_receivable_type", + field=models.BooleanField( + default=False, + help_text="Use the override receivable type from rent in " + "automatic invoices, if it is present. When creating a rent, some " + "service units (such as AKV and KuVa) want to select a receivable " + "type to be used in future automatic invoices. This helps avoid " + "some technical difficulties in invoice XML generation. " + "Generation logic would otherwise be unaware of the desired " + "receivable type, if it is different from the service unit's " + "default receivable type, or the leasetype's receivable type.", + verbose_name="Use the override receivable type from rent in automatic invoices?", + ), + ), + ] diff --git a/leasing/models/service_unit.py b/leasing/models/service_unit.py index c3f0b5c4..5f6df1ef 100644 --- a/leasing/models/service_unit.py +++ b/leasing/models/service_unit.py @@ -70,6 +70,21 @@ class ServiceUnit(TimeStampedSafeDeleteModel): blank=True, on_delete=models.PROTECT, ) + use_rent_override_receivable_type = models.BooleanField( + verbose_name=_( + "Use the override receivabletype from rent in automatic invoices?" + ), + help_text=_( + "Use the override receivable type from rent in automatic invoices, if " + "it is present. When creating a rent, some service units (such as AKV " + "and KuVa) want to select a receivable type to be used in future " + "automatic invoices. This helps avoid some technical difficulties in " + "invoice XML generation. Generation logic would otherwise be unaware " + "of the desired receivable type, if it is different from the service " + "unit's default receivable type, or the leasetype's receivable type." + ), + default=False, + ) recursive_get_related_skip_relations = [ "contacts", diff --git a/leasing/serializers/service_unit.py b/leasing/serializers/service_unit.py index 296fbb9a..1e507c17 100644 --- a/leasing/serializers/service_unit.py +++ b/leasing/serializers/service_unit.py @@ -12,4 +12,5 @@ class Meta: "id", "name", # "description", + "use_rent_override_receivable_type", ) diff --git a/leasing/viewsets/service_unit.py b/leasing/viewsets/service_unit.py index 2c95ff78..5df4667f 100644 --- a/leasing/viewsets/service_unit.py +++ b/leasing/viewsets/service_unit.py @@ -18,5 +18,6 @@ class ServiceUnitViewSet(ReadOnlyModelViewSet): "id", "name", "description", + "use_rent_override_receivable_type", ) ordering = ("name",)