Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
added farmer details in generation of farmer demo data
Browse files Browse the repository at this point in the history
  • Loading branch information
reichie020212 committed Feb 2, 2024
1 parent 55bdec0 commit cad4b00
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
1 change: 1 addition & 0 deletions spp_farmer_registry_demo/models/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ class Farmer(models.Model):
("certificate", "Certificate"),
("diploma", "Diploma"),
("university", "University"),
("tertiary", "Tertiary"),
],
)
100 changes: 77 additions & 23 deletions spp_farmer_registry_demo/models/generate_farmer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import random
import string
from datetime import datetime, timedelta

from faker import Faker

Expand Down Expand Up @@ -57,31 +58,10 @@ def _generate_sample_data(self, **kwargs):
num_groups = min(res.num_groups, 1000)

for i in range(0, num_groups):
locale = random.choice(locales)
sex = random.choice(sex_choice_range)
last_name = fake[locale].last_name()
first_name = (
fake[locale].first_name_male()
if sex == "Male"
else fake[locale].first_name_female()
group_id = res._generate_group_data(
i, fake, locales, sex_choice_range, kind_farm_id
)

group_name = f"{last_name} Farm"
id_group = (
"demo." + hashlib.md5(f"{group_name} {i}".encode("UTF-8")).hexdigest()
)

group_vals = {
"id": id_group,
"name": group_name,
"kind": kind_farm_id,
"is_registrant": True,
"is_group": True,
"farmer_family_name": last_name,
"farmer_given_name": first_name,
}
group_id = self.env["res.partner"].create(group_vals)

land_record_id = res._generate_land_record_record(group_id)
group_id.farm_land_rec_id = land_record_id.id

Expand Down Expand Up @@ -141,6 +121,80 @@ def _generate_sample_data(self, **kwargs):

return {"result": msg, "res_model": self._name, "res_ids": [res_id]}

def _generate_group_data(self, index, fake, locales, sex_choice_range, kind_id):
locale = random.choice(locales)
sex = random.choice(sex_choice_range)
last_name = fake[locale].last_name()
first_name = (
fake[locale].first_name_male()
if sex == "Male"
else fake[locale].first_name_female()
)
addl_name = (
fake[locale].first_name_male()
if sex == "Male"
else fake[locale].first_name_female()
)

group_name = f"{last_name} Farm"
id_group = (
"demo." + hashlib.md5(f"{group_name} {index}".encode("UTF-8")).hexdigest()
)

highest_education_level = [
"none",
"primary",
"secondary",
"tertiary",
]

marital_status = [
"single",
"married_monogamous",
"married_polygamous",
"widowed",
"separated",
]

farmer_mobile_tel = "+2547" + "".join(random.choices("0123456789", k=8))

start_date = datetime(year=1950, month=1, day=1)
end_date = datetime(year=2003, month=12, day=31)
time_between_dates = end_date - start_date
days_between_dates = time_between_dates.days
random_number_of_days = random.randrange(days_between_dates)
farmer_birthdate = start_date + timedelta(days=random_number_of_days)
farmer_email = (
"".join(random.choices("abcdefghijklmnopqrstuvwxyz0123456789", k=5))
+ "@example.com"
)
farmer_household_size = str(random.randint(1, 10))
farmer_postal_address = "P.O Box " + "".join(random.choices("0123456789", k=4))

group_vals = {
"id": id_group,
"name": group_name,
"kind": kind_id,
"is_registrant": True,
"is_group": True,
"farmer_family_name": last_name,
"farmer_given_name": first_name,
"farmer_national_id": "".join(
random.choices(string.ascii_uppercase + string.digits, k=10)
),
"farmer_sex": sex,
"farmer_addtnl_name": addl_name,
"farmer_marital_status": random.choice(marital_status),
"farmer_highest_education_level": random.choice(highest_education_level),
"farmer_mobile_tel": farmer_mobile_tel,
"farmer_birthdate": farmer_birthdate,
"farmer_email": farmer_email,
"farmer_formal_agricultural": random.choice([True, False]),
"farmer_household_size": farmer_household_size,
"farmer_postal_address": farmer_postal_address,
}
return self.env["res.partner"].create(group_vals)

def _generate_land_record_record(self, group_id):
land_name = "My Farm"
latitude, longitude = random_location_in_kenya()
Expand Down

0 comments on commit cad4b00

Please sign in to comment.