update script to populate data for Colombian companies
This commit is contained in:
		| @@ -3,7 +3,6 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser | |||||||
| from proteus import Model, Wizard | from proteus import Model, Wizard | ||||||
| from proteus import config as pconfig | from proteus import config as pconfig | ||||||
|  |  | ||||||
| import country |  | ||||||
| import currency | import currency | ||||||
| import company as company_ | import company as company_ | ||||||
| import parties | import parties | ||||||
| @@ -70,16 +69,13 @@ def main(database, modules, demo_password, company_config, config_file=None): | |||||||
|     config = set_config(database, config_file) |     config = set_config(database, config_file) | ||||||
|     to_activate, activated = activate_modules(config, modules) |     to_activate, activated = activate_modules(config, modules) | ||||||
|  |  | ||||||
|     if 'country' in to_activate or 'country' in activated: |  | ||||||
|         country.do_import() |  | ||||||
|  |  | ||||||
|     if 'currency' in to_activate or 'currency' in activated: |     if 'currency' in to_activate or 'currency' in activated: | ||||||
|         currency.do_import() |         currency.do_import() | ||||||
|  |  | ||||||
|     if 'company' in to_activate: |     if 'company' in to_activate: | ||||||
|         company = company_.setup(config, activated, company_config) |         company = company_.setup(config, activated, company_config) | ||||||
|     elif 'company' in activated: |     elif 'company' in activated: | ||||||
|         if not (company := company_.get()): |         if not (company := company_.get(company_config)): | ||||||
|             company = company_.setup(config, activated, company_config) |             company = company_.setup(config, activated, company_config) | ||||||
|         else: |         else: | ||||||
|             company = company |             company = company | ||||||
| @@ -87,7 +83,7 @@ def main(database, modules, demo_password, company_config, config_file=None): | |||||||
|         company = None |         company = None | ||||||
|  |  | ||||||
|     setup_languages(config, demo_password, company_config, company=company) |     setup_languages(config, demo_password, company_config, company=company) | ||||||
|     parties.setup_parties(database=database, config_file=config_file) |     # parties.setup_parties(database=database, config_file=config_file) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|   | |||||||
| @@ -11,9 +11,8 @@ path = "".join([dir, "/", file_]) | |||||||
|  |  | ||||||
|  |  | ||||||
| def setup(config, modules, company_config): | def setup(config, modules, company_config): | ||||||
|     data, = open_file(path) |  | ||||||
|  |  | ||||||
|     Address = Model.get('party.address') |     Identifier = Model.get('party.identifier') | ||||||
|     Company = Model.get('company.company') |     Company = Model.get('company.company') | ||||||
|     Country = Model.get('country.country') |     Country = Model.get('country.country') | ||||||
|     Currency = Model.get('currency.currency') |     Currency = Model.get('currency.currency') | ||||||
| @@ -31,28 +30,45 @@ def setup(config, modules, company_config): | |||||||
|     company_currency.save() |     company_currency.save() | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         company_country, = Country.find([('code', '=', company_config["company_country"])]) |         company_country, = Country.find( | ||||||
|  |             [('code', '=', company_config["company_country"])]) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|         company_country = None |         company_country = None | ||||||
|  |  | ||||||
|  |     try: | ||||||
|  |         company_subdivision, = Subdivision.find( | ||||||
|  |             [('code', '=', company_config["company_subdivision"])] | ||||||
|  |         ) | ||||||
|  |     except ValueError: | ||||||
|  |         company_subdivision = None | ||||||
|  |  | ||||||
|  |     try: | ||||||
|  |         company_municipality, = Subdivision.find( | ||||||
|  |             [('code', '=', company_config["company_municipality"])] | ||||||
|  |         ) | ||||||
|  |     except ValueError: | ||||||
|  |         company_municipality = None | ||||||
|  |  | ||||||
|     CompanyWizard = Wizard('company.company.config') |     CompanyWizard = Wizard('company.company.config') | ||||||
|     CompanyWizard.execute('company') |     CompanyWizard.execute('company') | ||||||
|  |  | ||||||
|     company = CompanyWizard.form |     company = CompanyWizard.form | ||||||
|     party = Party(name=data.get("name")) |     party = Party( | ||||||
|  |         name=company_config["company_name"], | ||||||
|  |         type_person=company_config["type_person"] | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     address = Address() |     identifier = Identifier() | ||||||
|     address.street = data.get("street") |     identifier.type = company_config["company_identifier_type"] | ||||||
|     address.city = data.get("city") |     identifier.code = company_config["company_identifier"] | ||||||
|  |  | ||||||
|  |     party.identifiers.append(identifier) | ||||||
|  |  | ||||||
|  |     address = party.addresses[0] | ||||||
|  |     address.street = company_config["company_street"] | ||||||
|     address.country = company_country |     address.country = company_country | ||||||
|  |     address.subdivision = company_subdivision | ||||||
|     try: |     address.subdivision_municipality = company_municipality | ||||||
|         address.subdivision, = Subdivision.find([ |  | ||||||
|             ('code', '=', company_config["company_subdivision"]) |  | ||||||
|         ]) |  | ||||||
|     except ValueError: |  | ||||||
|         pass |  | ||||||
|  |  | ||||||
|     party.addresses.append(address) |     party.addresses.append(address) | ||||||
|     party.save() |     party.save() | ||||||
| @@ -71,11 +87,12 @@ def setup(config, modules, company_config): | |||||||
|     return company |     return company | ||||||
|  |  | ||||||
|  |  | ||||||
| def get(): | def get(company_config): | ||||||
|  |  | ||||||
|     data, = open_file(path) |  | ||||||
|     Company = Model.get('company.company') |     Company = Model.get('company.company') | ||||||
|  |  | ||||||
|     if company := Company.find([('party.name', '=', data.get("name"))]): |     if company := Company.find([ | ||||||
|  |         ('party.name', '=', company_config["company_name"]) | ||||||
|  |     ]): | ||||||
|         return company |         return company | ||||||
|     return |     return | ||||||
|   | |||||||
| @@ -1,6 +1,12 @@ | |||||||
| { | { | ||||||
|  |   "company_name": "Empresa S.A.S", | ||||||
|  |   "type_person": "1", | ||||||
|  |   "company_identifier_type": "31", | ||||||
|  |   "company_identifier": "901222999", | ||||||
|  |   "company_street": "Av Das Valiquirias", | ||||||
|   "company_country": "CO", |   "company_country": "CO", | ||||||
|   "company_subdivision": "CO-CUN", |   "company_subdivision": "CO-05", | ||||||
|  |   "company_municipality": "CO-05001", | ||||||
|   "languages": { |   "languages": { | ||||||
|     "codes": ["en", "pt", "es", "es_419"] |     "codes": ["en", "pt", "es", "es_419"] | ||||||
|   }, |   }, | ||||||
| @@ -15,6 +21,7 @@ | |||||||
|     "country", |     "country", | ||||||
|     "currency", |     "currency", | ||||||
|     "party", |     "party", | ||||||
|  |     "party_co", | ||||||
|     "product", |     "product", | ||||||
|     "sale_point" |     "sale_point" | ||||||
|   ] |   ] | ||||||
|   | |||||||
| @@ -1,2 +1,2 @@ | |||||||
| name,street,City | name,street,country,subdivision,municipality,identifier_type,identifier | ||||||
| Empresa,Av Oriental,Medellin | Empresa,Av Oriental,Colombia,Cundinamarca,Medellin,13,90100000 | ||||||
|   | |||||||
| 
 | 
 Submodule modules/party_co updated: 3fb258e8a3...b80e2dbf45
									
								
							
		Reference in New Issue
	
	Block a user