|
4 | 4 | Usage: |
5 | 5 | python manage.py seed_data --email admin@example.com |
6 | 6 | python manage.py seed_data --email admin@example.com --orgs 2 --leads 100 --seed 42 |
| 7 | + python manage.py seed_data --email admin@example.com --currency EUR --country DE |
7 | 8 | python manage.py seed_data --email admin@example.com --clear --no-input |
8 | 9 | """ |
9 | 10 |
|
@@ -82,6 +83,24 @@ class Command(BaseCommand): |
82 | 83 | "Inbound", |
83 | 84 | ] |
84 | 85 |
|
| 86 | + # Country code to Faker locale mapping |
| 87 | + COUNTRY_FAKER_LOCALES = { |
| 88 | + "US": "en_US", |
| 89 | + "GB": "en_GB", |
| 90 | + "CA": "en_CA", |
| 91 | + "AU": "en_AU", |
| 92 | + "DE": "de_DE", |
| 93 | + "FR": "fr_FR", |
| 94 | + "IN": "en_IN", |
| 95 | + "JP": "ja_JP", |
| 96 | + "CN": "zh_CN", |
| 97 | + "BR": "pt_BR", |
| 98 | + "MX": "es_MX", |
| 99 | + "SG": "en_SG", |
| 100 | + "AE": "ar_AE", |
| 101 | + "CH": "de_CH", |
| 102 | + } |
| 103 | + |
85 | 104 | # Team name templates |
86 | 105 | TEAM_NAMES = [ |
87 | 106 | ("Sales Team", "Primary sales team handling all inbound leads"), |
@@ -182,6 +201,22 @@ def add_arguments(self, parser): |
182 | 201 | help="Tags per organization (default: 5)", |
183 | 202 | ) |
184 | 203 |
|
| 204 | + # Locale options |
| 205 | + valid_currencies = [c[0] for c in CURRENCY_CODES] |
| 206 | + parser.add_argument( |
| 207 | + "--currency", |
| 208 | + type=str, |
| 209 | + default="USD", |
| 210 | + choices=valid_currencies, |
| 211 | + help=f"Default currency for organizations (default: USD). Choices: {', '.join(valid_currencies)}", |
| 212 | + ) |
| 213 | + parser.add_argument( |
| 214 | + "--country", |
| 215 | + type=str, |
| 216 | + default="US", |
| 217 | + help="Default country code for organizations (default: US). Examples: US, GB, CA, AU, DE, FR, IN", |
| 218 | + ) |
| 219 | + |
185 | 220 | # Invoice-related arguments |
186 | 221 | parser.add_argument( |
187 | 222 | "--products", |
@@ -238,19 +273,25 @@ def add_arguments(self, parser): |
238 | 273 | ) |
239 | 274 |
|
240 | 275 | def handle(self, *args, **options): |
241 | | - # Initialize Faker |
| 276 | + # Initialize Faker with locale matching the country |
| 277 | + country = options["country"].upper() |
| 278 | + locale = self.COUNTRY_FAKER_LOCALES.get(country, "en_US") |
| 279 | + |
242 | 280 | seed = options.get("seed") |
243 | 281 | if seed: |
244 | 282 | random.seed(seed) |
245 | | - self.fake = Faker(["en_US"]) |
| 283 | + self.fake = Faker([locale]) |
246 | 284 | Faker.seed(seed) |
247 | 285 | else: |
248 | | - self.fake = Faker(["en_US", "en_GB", "en_CA", "en_AU"]) |
| 286 | + self.fake = Faker([locale]) |
249 | 287 |
|
250 | 288 | # Initialize InvoiceSeeder |
251 | 289 | self.invoice_seeder = InvoiceSeeder(self.fake, self.stdout) |
252 | 290 |
|
253 | 291 | self.stdout.write(self.style.MIGRATE_HEADING("Seeding CRM database...")) |
| 292 | + self.stdout.write( |
| 293 | + f"Currency: {options['currency']}, Country: {country}, Locale: {locale}" |
| 294 | + ) |
254 | 295 | if seed: |
255 | 296 | self.stdout.write(f"Using seed: {seed}") |
256 | 297 |
|
@@ -334,7 +375,7 @@ def seed_all(self, options): |
334 | 375 | """Main seeding orchestration.""" |
335 | 376 | for i in range(options["orgs"]): |
336 | 377 | self.stdout.write(f"\n--- Organization {i + 1}/{options['orgs']} ---") |
337 | | - org = self.create_org() |
| 378 | + org = self.create_org(options["currency"], options["country"]) |
338 | 379 | # Set RLS context for this org before creating org-scoped data |
339 | 380 | self.set_rls_context(org.id) |
340 | 381 | profiles = self.create_profiles( |
@@ -404,15 +445,12 @@ def seed_all(self, options): |
404 | 445 | options["tasks"], |
405 | 446 | ) |
406 | 447 |
|
407 | | - def create_org(self): |
| 448 | + def create_org(self, currency, country): |
408 | 449 | """Create an organization.""" |
409 | | - currencies = [c[0] for c in CURRENCY_CODES] |
410 | | - countries = ["US", "GB", "CA", "AU", "DE", "FR", "IN"] |
411 | | - |
412 | 450 | org = Org.objects.create( |
413 | 451 | name=self.fake.company(), |
414 | | - default_currency=random.choice(currencies), |
415 | | - default_country=random.choice(countries), |
| 452 | + default_currency=currency, |
| 453 | + default_country=country, |
416 | 454 | ) |
417 | 455 | self.stats["orgs"] += 1 |
418 | 456 | self.stdout.write( |
@@ -524,7 +562,7 @@ def create_contacts(self, org, profiles, teams, tags, count): |
524 | 562 | city=self.fake.city(), |
525 | 563 | state=self.fake.state_abbr(), |
526 | 564 | postcode=self.fake.postcode(), |
527 | | - country=random.choice(["US", "GB", "CA", "AU"]), |
| 565 | + country=org.default_country or "US", |
528 | 566 | description=self.fake.paragraph() if random.random() > 0.5 else None, |
529 | 567 | org=org, |
530 | 568 | ) |
|
0 commit comments