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

Features/cf checks #91

Merged
merged 2 commits into from
Oct 28, 2023
Merged
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
12 changes: 6 additions & 6 deletions asso/member/fixtures/member/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
user: 2
first_name: "John"
last_name: "Doe"
social_card: AAAAAAAAAAAAAAAA
social_card: DOEJHN70A01Z114S
gender: M
birth_date: 1970-01-01
birth_city: "London"
birth_city: "United Kingdom"
birth_province: 1
phone: +44 000 0000000
document_type: "carta-identita"
Expand All @@ -33,10 +33,10 @@
user: 3
first_name: "Johanna"
last_name: "Doe"
social_card: AAAAAAAAAAAAAAAA
social_card: DOEJNN70A41Z114Z
gender: F
birth_date: 1970-01-01
birth_city: "London"
birth_city: "United Kingdom"
birth_province: 1
phone: +44 000 0000000
document_type: "carta-identita"
Expand All @@ -53,10 +53,10 @@
updated_at: 2023-01-02T00:00:00Z
first_name: "John"
last_name: "Doe"
social_card: AAAAAAAAAAAAAAAA
social_card: DOEJHN70A01Z114S
gender: M
birth_date: 1970-01-01
birth_city: "London"
birth_city: "United Kingdom"
birth_province: 1
- model: member.MemberPermanentAddress
pk: 1
Expand Down
28 changes: 28 additions & 0 deletions asso/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ class MemberPersonalData(models.Model):
def full_name(self) -> str:
return f"{self.first_name} {self.last_name}"

def check_social_card(self):
return codicefiscale.is_valid(self.social_card)

def check_first_name(self):
decoded = codicefiscale.decode_raw(self.social_card)
return codicefiscale.encode_firstname(self.first_name) == decoded["firstname"]

def check_last_name(self):
decoded = codicefiscale.decode_raw(self.social_card)
return codicefiscale.encode_lastname(self.last_name) == decoded["lastname"]

def check_birth_date(self):
bd = codicefiscale.decode_raw(self.social_card)["birthdate"]
res = False
if self.gender != Gender.FEMALE:
res |= codicefiscale.encode_birthdate(str(self.birth_date), "M") == bd
if self.gender != Gender.MALE:
res |= codicefiscale.encode_birthdate(str(self.birth_date), "F") == bd
return res

def check_personal_data(self):
return (
self.check_social_card()
and self.check_first_name()
and self.check_last_name()
and self.check_birth_date()
)

class Meta:
abstract = True

Expand Down