From 051ad8c2ca3d4dee562af5a63576c50f54505006 Mon Sep 17 00:00:00 2001 From: aserrador Date: Mon, 20 Oct 2025 13:10:37 -0500 Subject: [PATCH] Se agrupan script para poblar informacion --- Rakefile | 2 +- demo/__main__.py | 106 ----------------------------------------------- demo/company.py | 98 ------------------------------------------- demo/country.py | 24 ----------- demo/currency.py | 16 ------- demo/parties.py | 39 ----------------- demo/tools.py | 10 ----- 7 files changed, 1 insertion(+), 294 deletions(-) delete mode 100644 demo/__main__.py delete mode 100644 demo/company.py delete mode 100644 demo/country.py delete mode 100644 demo/currency.py delete mode 100644 demo/parties.py delete mode 100644 demo/tools.py diff --git a/Rakefile b/Rakefile index 3fbafb4..cb8db4e 100644 --- a/Rakefile +++ b/Rakefile @@ -91,7 +91,7 @@ namespace :live do compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'createdb -U tryton #{args.database}'") compose('restart', "live", compose: "compose.live.yml") sleep(30) - compose('exec', 'live', "bash -c 'python3 demo/__main__.py -c .dev/trytond.cfg -d #{args.database}'") + compose('exec', 'live', "bash -c 'python3 demo/scripts/__main__.py -c .dev/trytond.cfg -d #{args.database}'") compose('restart', 'live', compose: "compose.live.yml") else puts "Falta el nombre de la base de datos" diff --git a/demo/__main__.py b/demo/__main__.py deleted file mode 100644 index f6191a3..0000000 --- a/demo/__main__.py +++ /dev/null @@ -1,106 +0,0 @@ -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser - -from proteus import Model, Wizard -from proteus import config as pconfig - -import currency -import company as company_ -import parties - -import json - - -def set_config(database, config_file): - return pconfig.set_trytond(database, config_file=config_file) - - -def activate_modules(config, modules): - Module = Model.get('ir.module') - modules = Module.find([ - ('name', 'in', modules), - ]) - - for module in modules: - if module.state == 'activate': - module.click('upgrade') - else: - module.click('activate') - - modules = [m.name for m in Module.find([('state', '=', 'to_activate')])] - Wizard('ir.module.activate_upgrade').execute('upgrade') - - ConfigWizardItem = Model.get('ir.module.config_wizard.item') - for item in ConfigWizardItem.find([('state', '!=', 'done')]): - item.state = 'done' - item.save() - - activated_modules = [ - m.name for m in Module.find([('state', '=', 'activated')]) - ] - - return modules, activated_modules - - -def setup_languages(config, demo_password, company_config, company=None): - User = Model.get('res.user') - Lang = Model.get('ir.lang') - Action = Model.get('ir.action') - - langs = Lang.find([("code", "in", company_config["languages"]["codes"])]) - Lang.click(langs, 'load_translations') - - company_lang, = Lang.find([ - ("code", "=", company_config["company_language"]) - ]) - - admin, = User.find( - [("id", "=", 1)] - ) - # Use root to skip password validation - - menu, = Action.find([('usage', '=', 'menu')]) - - admin.menu = menu - admin.language = company_lang - admin.save() - - -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 '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(company_config)): - company = company_.setup(config, activated, company_config) - else: - company = company - else: - company = None - - setup_languages(config, demo_password, company_config, company=company) - # parties.setup_parties(database=database, config_file=config_file) - - -if __name__ == '__main__': - with open('demo/data/config.json') as file: - config_tryton = json.load(file) - - parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) - parser.add_argument('-c', '--config', dest='config_file') - parser.add_argument('-m', '--module', dest='modules', nargs='+', - help='module to activate', default=config_tryton.get( - "modules")) - - parser.add_argument('--demo_password', dest='demo_password', - default='demo', help='demo password') - parser.add_argument('-d', '--database', dest='database', - default='demo', help="database name") - options = parser.parse_args() - - main(options.database, options.modules, options.demo_password, - config_file=options.config_file, company_config=config_tryton) diff --git a/demo/company.py b/demo/company.py deleted file mode 100644 index c4d351c..0000000 --- a/demo/company.py +++ /dev/null @@ -1,98 +0,0 @@ -import datetime as dt -from decimal import Decimal - -from proteus import Model, Wizard - -from tools import open_file - -dir = "./demo/data" -file_ = "party_company.csv" -path = "".join([dir, "/", file_]) - - -def setup(config, modules, company_config): - - Identifier = Model.get('party.identifier') - Company = Model.get('company.company') - Country = Model.get('country.country') - Currency = Model.get('currency.currency') - Party = Model.get('party.party') - Subdivision = Model.get('country.subdivision') - - company_currency, = Currency.find([ - ('code', '=', company_config["company_currency"]) - ]) - - 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"])]) - 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=company_config["company_name"], - type_person=company_config["type_person"] - ) - - 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() - - company.party = party - company.currency = company_currency - company.timezone = company_config["company_timezone"] - CompanyWizard.execute('add') - - # Reload context - User = Model.get('res.user') - config._context = User.get_preferences(True, {}) - - company, = Company.find() - - return company - - -def get(company_config): - - Company = Model.get('company.company') - - if company := Company.find([ - ('party.name', '=', company_config["company_name"]) - ]): - return company - return diff --git a/demo/country.py b/demo/country.py deleted file mode 100644 index bae451c..0000000 --- a/demo/country.py +++ /dev/null @@ -1,24 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. - -import subprocess -import sys - -try: - import pycountry -except ImportError: - subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pycountry']) - import pycountry - - -try: - from trytond.modules.country.scripts.import_countries import do_import -except ImportError: - def do_import(*args, **kwargs): - pass - -__all__ = [do_import] - - -if __name__ == '__main__': - do_import() diff --git a/demo/currency.py b/demo/currency.py deleted file mode 100644 index d2d83a9..0000000 --- a/demo/currency.py +++ /dev/null @@ -1,16 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. -from proteus import Model - -try: - from trytond.modules.currency.scripts.import_currencies import do_import -except ImportError: - def do_import(*args, **kwargs): - Currency = Model.get('currency.currency') - usd = Currency(name="USD", code='USD') - usd.save() - -__all__ = [do_import] - -if __name__ == '__main__': - do_import() diff --git a/demo/parties.py b/demo/parties.py deleted file mode 100644 index 6d2501f..0000000 --- a/demo/parties.py +++ /dev/null @@ -1,39 +0,0 @@ -from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser -from proteus import Model -from proteus import config as pconfig - -from tools import open_file - -import json - -dir = "./demo/data" -file_ = "parties.csv" -path = "".join([dir, "/", file_]) - - -def set_config(database, config_file): - return pconfig.set_trytond(database, config_file=config_file) - - -def setup_parties(database, config_file): - set_config(database, config_file) - data = open_file(path) - - Party = Model.get("party.party") - parties = [ - Party(name=r.get("Name")) for r in data] - - return Party.save(parties) - - -if __name__ == '__main__': - with open('demo/data/config.json') as file: - config_tryton = json.load(file) - - parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) - parser.add_argument('-c', '--config', dest='config_file') - parser.add_argument('-d', '--database', dest='database', - default='demo', help="database name") - options = parser.parse_args() - - setup_parties(options.database, options.config_file) diff --git a/demo/tools.py b/demo/tools.py deleted file mode 100644 index 8adb5e8..0000000 --- a/demo/tools.py +++ /dev/null @@ -1,10 +0,0 @@ -import csv - -def open_file(file_path): - content = [] - with open(file_path, mode='r', encoding='utf-8') as csvfile: - data = csv.DictReader(csvfile) - for row in data: - content.append(row) - - return content