831e656fa3
- Add MessageTemplate.runtime_field_labels so mobile's per-field execution-time labels are actually persisted (were silently dropped) - Fix AdvanceOrderStageView reading the wrong extra-input key, and be honest about SMS send failures instead of always claiming success - Add admin gift-gem SMS notification via Kavenegar - Post real double-entry Transactions for plain (non-invoice) ledger entries so trial balance, the معین screen, and CSV/XLSX exports actually include everyday income/expense entries; backfill existing historical entries via data migration - Rewrite CSV ledger export to produce an actual دفتر معین structure (per-account running balance) instead of a flat row dump - Add invoice percent/promotional discounts, tax presets, ledger discount-percent handling, product SKU/category/expiry fields, and manual ledger-book archiving (replacing auto-archive on new book) - Add reviews app (models, API, admin) for the comments/reviews feature - Update tests for the above; fix two stale assertions left over from earlier work in this branch (معین sheet name, book auto-close)
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
from rest_framework import serializers
|
|
|
|
from apps.banker.models import Contact, ContactField, ContactGroup, MessageTemplate
|
|
|
|
# نکته: id هر رکورد را خودِ اپ (UUID) تولید میکند و روی سرور هم همان مقدار
|
|
# استفاده میشود. چون هر بار /backup/ کل رکوردهای کاربر جایگزین میشوند (نه
|
|
# create تکی)، اعتبارسنج یکتابودنِ خودکار DRF روی id باید خاموش شود؛ وگرنه
|
|
# از دومین بکاپ به بعد چون همان idها از قبل در دیتابیس هست، validation رد
|
|
# میشود.
|
|
_ID_NO_UNIQUE_CHECK = {"id": {"validators": []}}
|
|
|
|
|
|
class ContactGroupSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ContactGroup
|
|
fields = ["id", "name", "color", "is_general", "member_ids"]
|
|
extra_kwargs = _ID_NO_UNIQUE_CHECK
|
|
|
|
|
|
class ContactFieldSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ContactField
|
|
fields = ["id", "group_id", "label", "sort_order"]
|
|
extra_kwargs = _ID_NO_UNIQUE_CHECK
|
|
|
|
|
|
class ContactSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Contact
|
|
fields = ["id", "name", "phone", "device_contact_id", "field_values", "channel_ids"]
|
|
extra_kwargs = _ID_NO_UNIQUE_CHECK
|
|
|
|
|
|
class MessageTemplateSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = MessageTemplate
|
|
fields = ["id", "group_id", "name", "body", "mode", "runtime_field_labels"]
|
|
extra_kwargs = _ID_NO_UNIQUE_CHECK
|
|
|
|
|
|
class BackupSerializer(serializers.Serializer):
|
|
"""عکس کامل وضعیت اپ روی یک کاربر — برای پشتیبانگیری/بازیابی"""
|
|
|
|
contact_fields = ContactFieldSerializer(many=True, required=False, default=list)
|
|
contacts = ContactSerializer(many=True, required=False, default=list)
|
|
groups = ContactGroupSerializer(many=True, required=False, default=list)
|
|
templates = MessageTemplateSerializer(many=True, required=False, default=list)
|