feat: issue OneTeam/Naliia_Dev#5
This commit is contained in:
		| @@ -11,6 +11,7 @@ if [ -z "${DEVELOP}" ]; then | |||||||
| fi | fi | ||||||
|  |  | ||||||
| if [ ${DEVELOP} = "True" ]; then | if [ ${DEVELOP} = "True" ]; then | ||||||
|  |   pip3 install --break-system-packages proteus==${TRYTOND_VERSION} | ||||||
|   pip3 install --break-system-packages -r .dev/requirements_dev.txt |   pip3 install --break-system-packages -r .dev/requirements_dev.txt | ||||||
| fi | fi | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								Rakefile
									
									
									
									
									
								
							| @@ -75,23 +75,21 @@ namespace :live do | |||||||
|  |  | ||||||
|   desc 'monitorear salida' |   desc 'monitorear salida' | ||||||
|   task :tail_end do |   task :tail_end do | ||||||
|     compose('logs', '-f', '-n 50', 'live.dev', compose: 'compose.live.yml') |     compose('logs', '-f', '-n 50', 'live', compose: 'compose.live.yml') | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   desc 'populate data' |   desc 'populate data' | ||||||
|   task :populate, [:database] do |_, args| |   task :populate, [:database] do |_, args| | ||||||
|     if args.database |     if args.database | ||||||
|       compose('stop', "live.dev", compose: "compose.yml") |       compose('stop', "live", compose: "compose.live.yml") | ||||||
|       compose('exec', '-it', '--user', 'postgres', 'db.dev', "bash -c 'dropdb -U tryton #{args.database}'") |       compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'dropdb -U tryton #{args.database}'") | ||||||
|       compose('exec', '-it', '--user', 'postgres', 'db.dev', "bash -c 'createdb -U tryton #{args.database}'") |       compose('exec', '-it', '--user', 'postgres', 'db', "bash -c 'createdb -U tryton #{args.database}'") | ||||||
|       compose('restart', "live.dev", compose: "compose.yml") |       compose('restart', "live", compose: "compose.live.yml") | ||||||
|  |  | ||||||
|       sleep(30) |       sleep(30) | ||||||
|       # compose('exec', '--user', 'root', 'live.dev', "trytond-admin -d #{args.database} -m --all -vv --act", compose: 'compose.yml') |       compose('exec', 'live', "bash -c 'python3 demo/__main__.py -c .dev/trytond.cfg -d #{args.database}'") | ||||||
|       compose('exec', 'live.dev', "bash -c 'python3 demo/__main__.py -c .dev/trytond.cfg -d #{args.database}'") |       compose('restart', 'live', compose: "compose.live.yml") | ||||||
|       compose('restart', 'live.dev', compose: "compose.yml") |  | ||||||
|     else |     else | ||||||
|       puts "Falta el nomnbre de la base de datos" |       puts "Falta el nombre de la base de datos" | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|   | |||||||
							
								
								
									
										110
									
								
								demo/__main__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								demo/__main__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,110 @@ | |||||||
|  | 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 | ||||||
|  |  | ||||||
|  | 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 '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()): | ||||||
|  |             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) | ||||||
							
								
								
									
										81
									
								
								demo/company.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								demo/company.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | |||||||
|  | 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): | ||||||
|  |     data, = open_file(path) | ||||||
|  |  | ||||||
|  |     Address = Model.get('party.address') | ||||||
|  |     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 | ||||||
|  |  | ||||||
|  |      | ||||||
|  |     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 | ||||||
|  |  | ||||||
|  |     try: | ||||||
|  |         address.subdivision, = Subdivision.find([ | ||||||
|  |             ('code', '=', company_config["company_subdivision"]) | ||||||
|  |         ]) | ||||||
|  |     except ValueError: | ||||||
|  |         pass | ||||||
|  |  | ||||||
|  |     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(): | ||||||
|  |  | ||||||
|  |     data, = open_file(path) | ||||||
|  |     Company = Model.get('company.company') | ||||||
|  |  | ||||||
|  |     if company := Company.find([('party.name', '=', data.get("name"))]): | ||||||
|  |         return company | ||||||
|  |     return  | ||||||
							
								
								
									
										24
									
								
								demo/country.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								demo/country.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | # 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() | ||||||
							
								
								
									
										16
									
								
								demo/currency.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								demo/currency.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | # 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() | ||||||
							
								
								
									
										22
									
								
								demo/data/config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								demo/data/config.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | { | ||||||
|  |   "company_country": "CO", | ||||||
|  |   "company_subdivision": "CO-CUN", | ||||||
|  |   "languages": { | ||||||
|  |     "codes": ["en", "pt", "es", "es_419"] | ||||||
|  |   }, | ||||||
|  |   "company_language": "es_419", | ||||||
|  |   "company_timezone": "America/Bogota", | ||||||
|  |   "currencies": { | ||||||
|  |     "codes": ["USD", "BRL", "COP"] | ||||||
|  |   }, | ||||||
|  |   "company_currency": "COP", | ||||||
|  |   "modules": [ | ||||||
|  |     "company", | ||||||
|  |     "country", | ||||||
|  |     "currency", | ||||||
|  |     "party", | ||||||
|  |     "product", | ||||||
|  |     "sale_point" | ||||||
|  |   ] | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										18
									
								
								demo/data/parties.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								demo/data/parties.csv
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | Name,Farm Code | ||||||
|  | Gottfried Jauer,00 | ||||||
|  | Alex Sandro Da Silva,01 | ||||||
|  | Joseraldo Martins,02 | ||||||
|  | Lauri Jose Machado,03 | ||||||
|  | Christian Verenka Martins,04 | ||||||
|  | Everton José Machado,05 | ||||||
|  | Lurdes F. Jacom Da Silva,06 | ||||||
|  | Cristiane Fernandes,07 | ||||||
|  | Flavio Schuster,08 | ||||||
|  | Pedro Henrique,09 | ||||||
|  | Sirlei Riepe,10 | ||||||
|  | Sergio Ferreira Das Neves,11 | ||||||
|  | Valdecir De Souza Machado,12 | ||||||
|  | Egeziel Mendez,13 | ||||||
|  | Aparecida de Fátima Emilio,14 | ||||||
|  | Lucimara França Correa,15 | ||||||
|  | Valdecir Alves de Freitas,"" | ||||||
| 
 | 
							
								
								
									
										2
									
								
								demo/data/party_company.csv
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								demo/data/party_company.csv
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | name,street,City | ||||||
|  | Empresa,Av Oriental,Medellin | ||||||
| 
 | 
							
								
								
									
										39
									
								
								demo/parties.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								demo/parties.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | |||||||
|  | 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) | ||||||
							
								
								
									
										10
									
								
								demo/tools.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								demo/tools.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | 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 | ||||||
		Reference in New Issue
	
	Block a user