Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OM-51: generate qr for insuree #83

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions insuree/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

}

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions insuree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 23 additions & 1 deletion insuree/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading