diff --git a/insuree/apps.py b/insuree/apps.py index 0d002b8..5a8d30e 100644 --- a/insuree/apps.py +++ b/insuree/apps.py @@ -33,6 +33,8 @@ "validation_code_invalid_insuree_number_checksum": 4, "validation_code_invalid_insuree_number_exception": 5, "insuree_fsp_mandatory": False, + "insuree_generate_qr_code": False, + "insuree_notify_mconnect": False, } @@ -67,6 +69,8 @@ class InsureeConfig(AppConfig): insuree_number_length = None insuree_number_modulo_root = None insuree_fsp_mandatory = None + insuree_generate_qr_code = None + insuree_notify_mconnect = None def __load_config(self, cfg): for field in cfg: diff --git a/insuree/models.py b/insuree/models.py index bcdb8d8..9866996 100644 --- a/insuree/models.py +++ b/insuree/models.py @@ -375,3 +375,8 @@ class PolicyRenewalDetail(core_models.VersionedModel): class Meta: managed = True db_table = 'tblPolicyRenewalDetails' + + +class InsureeQr(core_models.HistoryModel): + insuree = models.ForeignKey('insuree.Insuree', models.DO_NOTHING, null=False, blank=False) + qr_svg = models.TextField(blank=False, null=False) diff --git a/insuree/services.py b/insuree/services.py index 0fc2cc3..6c653e1 100644 --- a/insuree/services.py +++ b/insuree/services.py @@ -10,9 +10,11 @@ from django.utils.translation import gettext as _ from core.signals import register_service_signal +from core.utils import generate_qr_code_svg from insuree.apps import InsureeConfig -from insuree.models import InsureePhoto, PolicyRenewalDetail, Insuree, Family, InsureePolicy +from insuree.models import InsureePhoto, PolicyRenewalDetail, Insuree, Family, InsureePolicy, InsureeQr from django.core.exceptions import ValidationError +from core.models import User logger = logging.getLogger(__name__) @@ -222,6 +224,22 @@ def load_photo_file(file_dir, file_name): return base64.b64encode(f.read()).decode("utf-8") +def create_or_update_insuree_qr(insuree): + user = User.objects.filter(i_user__id=insuree.audit_user_id).first() + data = { + "id": insuree.chf_id, + "first_name": insuree.other_names, + "last_name": insuree.last_name, + } + qr_code = generate_qr_code_svg(data) + instance = InsureeQr.objects.filter(insuree_id=insuree.id).first() + if instance: + instance.qr_svg = qr_code + else: + instance = InsureeQr(insuree_id=insuree.id, qr_svg=qr_code) + instance.save(username=user.username) + + class InsureeService: def __init__(self, user): self.user = user @@ -251,6 +269,10 @@ def create_or_update(self, data): insuree = Insuree.objects.create(**data) insuree.save() photo = handle_insuree_photo(self.user, now, insuree, photo) + if InsureeConfig.insuree_generate_qr_code: + create_or_update_insuree_qr(insuree) + if InsureeConfig.insuree_notify_mconnect: + pass if photo: insuree.photo = photo insuree.photo_date = photo.date