From 4c08ef4b21e27883bcfb75bb788ab766a0c92628 Mon Sep 17 00:00:00 2001 From: Shayan Azadi Date: Tue, 4 Aug 2026 19:21:37 +0330 Subject: [PATCH] =?UTF-8?q?Add=20voucher-line=20party=20(=D8=AA=D9=81?= =?UTF-8?q?=D8=B5=DB=8C=D9=84)=20and=20allow=20cache-control=20CORS=20head?= =?UTF-8?q?ers.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Supports accounting journal detail parties and preflight from the Vite client that sends Cache-Control/Pragma. Co-authored-by: Cursor --- .../migrations/0011_voucherline_party.py | 23 +++++++++++++++++++ accounting/models.py | 8 +++++++ accounting/serializers.py | 8 ++++++- config/settings.py | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 accounting/migrations/0011_voucherline_party.py diff --git a/accounting/migrations/0011_voucherline_party.py b/accounting/migrations/0011_voucherline_party.py new file mode 100644 index 0000000..40f7c0d --- /dev/null +++ b/accounting/migrations/0011_voucherline_party.py @@ -0,0 +1,23 @@ +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0010_voucher_regarding_invoiceline_event_name'), + ] + + operations = [ + migrations.AddField( + model_name='voucherline', + name='party', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='voucher_lines', + to='accounting.party', + ), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index b8bedfa..a3d608a 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -137,6 +137,14 @@ class VoucherLine(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) voucher = models.ForeignKey(Voucher, on_delete=models.CASCADE, related_name='lines') account = models.ForeignKey(Account, on_delete=models.PROTECT, related_name='voucher_lines') + # تفصیل / طرف حساب — who the line is with (optional for non-party accounts) + party = models.ForeignKey( + Party, + on_delete=models.SET_NULL, + null=True, + blank=True, + related_name='voucher_lines', + ) description = models.CharField(max_length=255, blank=True, default='') debit = models.FloatField(default=0) credit = models.FloatField(default=0) diff --git a/accounting/serializers.py b/accounting/serializers.py index 45bd839..c99d48d 100644 --- a/accounting/serializers.py +++ b/accounting/serializers.py @@ -65,10 +65,16 @@ class VoucherLineSerializer(serializers.ModelSerializer): # Lenient: accepts client-generated ids (ignored on write, recreated server-side). id = serializers.CharField(required=False) accountId = serializers.PrimaryKeyRelatedField(source='account', queryset=Account.objects.all()) + partyId = serializers.PrimaryKeyRelatedField( + source='party', + queryset=Party.objects.all(), + required=False, + allow_null=True, + ) class Meta: model = VoucherLine - fields = ['id', 'accountId', 'description', 'debit', 'credit'] + fields = ['id', 'accountId', 'partyId', 'description', 'debit', 'credit'] class VoucherSerializer(serializers.ModelSerializer): diff --git a/config/settings.py b/config/settings.py index b3404b5..9b0b11c 100644 --- a/config/settings.py +++ b/config/settings.py @@ -154,9 +154,11 @@ CORS_ALLOW_HEADERS = [ 'accept', 'accept-encoding', 'authorization', + 'cache-control', 'content-type', 'dnt', 'origin', + 'pragma', 'user-agent', 'x-csrftoken', 'x-requested-with',