From 4a8645aefadf76559847be8b4eb4c79570fb7ecf Mon Sep 17 00:00:00 2001 From: rodia Date: Fri, 5 Sep 2025 19:07:03 -0300 Subject: [PATCH] update script to populate data for Colombian companies --- demo/__main__.py | 8 ++--- demo/company.py | 59 ++++++++++++++++++++++++------------- demo/data/config.json | 9 +++++- demo/data/party_company.csv | 4 +-- modules/party_co | 2 +- 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/demo/__main__.py b/demo/__main__.py index c3ebb95..f6191a3 100644 --- a/demo/__main__.py +++ b/demo/__main__.py @@ -3,7 +3,6 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from proteus import Model, Wizard from proteus import config as pconfig -import country import currency import company as company_ import parties @@ -70,16 +69,13 @@ def main(database, modules, demo_password, company_config, config_file=None): config = set_config(database, config_file) 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: currency.do_import() if 'company' in to_activate: company = company_.setup(config, activated, company_config) elif 'company' in activated: - if not (company := company_.get()): + if not (company := company_.get(company_config)): company = company_.setup(config, activated, company_config) else: company = company @@ -87,7 +83,7 @@ def main(database, modules, demo_password, company_config, config_file=None): company = None 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__': diff --git a/demo/company.py b/demo/company.py index d1b13a6..c4d351c 100644 --- a/demo/company.py +++ b/demo/company.py @@ -11,9 +11,8 @@ path = "".join([dir, "/", file_]) 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') Country = Model.get('country.country') Currency = Model.get('currency.currency') @@ -27,32 +26,49 @@ def setup(config, modules, company_config): rate = company_currency.rates.new() rate.date = dt.date(dt.date.today().year, 1, 1) rate.rate = Decimal('1') - + company_currency.save() try: - company_country, = Country.find([('code', '=', company_config["company_country"])]) + company_country, = Country.find( + [('code', '=', company_config["company_country"])]) except ValueError: 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.execute('company') company = CompanyWizard.form - party = Party(name=data.get("name")) - - address = Address() - address.street = data.get("street") - address.city = data.get("city") - address.country = company_country + party = Party( + name=company_config["company_name"], + type_person=company_config["type_person"] + ) - try: - address.subdivision, = Subdivision.find([ - ('code', '=', company_config["company_subdivision"]) - ]) - except ValueError: - pass + identifier = Identifier() + identifier.type = company_config["company_identifier_type"] + 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.subdivision = company_subdivision + address.subdivision_municipality = company_municipality party.addresses.append(address) party.save() @@ -71,11 +87,12 @@ def setup(config, modules, company_config): return company -def get(): +def get(company_config): - data, = open_file(path) 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 + return diff --git a/demo/data/config.json b/demo/data/config.json index 6350d7a..ab62f82 100644 --- a/demo/data/config.json +++ b/demo/data/config.json @@ -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_subdivision": "CO-CUN", + "company_subdivision": "CO-05", + "company_municipality": "CO-05001", "languages": { "codes": ["en", "pt", "es", "es_419"] }, @@ -15,6 +21,7 @@ "country", "currency", "party", + "party_co", "product", "sale_point" ] diff --git a/demo/data/party_company.csv b/demo/data/party_company.csv index 59207da..f9cbb0a 100644 --- a/demo/data/party_company.csv +++ b/demo/data/party_company.csv @@ -1,2 +1,2 @@ -name,street,City -Empresa,Av Oriental,Medellin +name,street,country,subdivision,municipality,identifier_type,identifier +Empresa,Av Oriental,Colombia,Cundinamarca,Medellin,13,90100000 diff --git a/modules/party_co b/modules/party_co index 3fb258e..b80e2db 160000 --- a/modules/party_co +++ b/modules/party_co @@ -1 +1 @@ -Subproject commit 3fb258e8a3c574cb5205a6dab9ae2e3f7f5f1ad8 +Subproject commit b80e2dbf453ccac01f0f568e8cca31a291f79483