def test_translation_clean(self): translation_clean = Wizard('ir.translation.clean') self.assertEqual(translation_clean.form.__class__.__name__, 'ir.translation.clean.start') translation_clean.execute('clean') self.assertEqual(translation_clean.form.__class__.__name__, 'ir.translation.clean.succeed')
def crear_company(config, lang): """ Crear company. Traer datos de AFIP""" Currency = Model.get('currency.currency') Company = Model.get('company.company') Party = Model.get('party.party') # crear company # obtener nombre de la compania de un archivo. print u'\n>>> creando company...' import ConfigParser ini_config = ConfigParser.ConfigParser() ini_config.read('company.ini') currencies = Currency.find([('code', '=', 'ARS')]) currency, = currencies company_config = Wizard('company.company.config') company_config.execute('company') company = company_config.form party = Party(name='NOMBRE COMPANY') party.lang = lang party.vat_country = 'AR' try: party.vat_number = ini_config.get('company', 'cuit') party.iva_condition = ini_config.get('company', 'iva_condition') except Exception,e: print 'Error: No se ha configurado correctamente company.ini\n' raise SystemExit(repr(e))
def account_reconcile(database, lines=2, months=6, config_file=os.environ.get('TRYTOND_CONFIG')): pref = config.set_trytond(database=database, config_file=config_file) Module = Model.get('ir.module.module') Company = Model.get('company.company') modules = Module.find([ ('name', '=', 'account_reconcile'), ]) if not modules: print t.bold('Module account_reconcile not found') return reconcile, = modules if reconcile.state != 'installed': Module.install([reconcile.id], pref.context) Wizard('ir.module.module.install_upgrade').execute('upgrade') for company in Company.find([]): print t.bold('Start reconcile for company %s (Lines %s, Months %s)' % (company.rec_name, lines, months)) with pref.set_context({'company': company.id}): reconcile = Wizard('account.move_reconcile') reconcile.form.max_lines = str(lines) reconcile.form.max_months = months reconcile.form.start_date = None reconcile.form.end_date = None reconcile.execute('reconcile')
def automatic_reconciliation(database, max_lines=4, config_file=os.environ.get('TRYTOND_CONFIG')): """ Launch Automatic Reconciliation wizard for all databases and years """ if not database: return print t.bold("Automatic Reconciliation for %s" % database) if not check_database(database, {}): return config = pconfig.set_trytond(database=database, config_file=config_file) Company = Model.get('company.company') FiscalYear = Model.get('account.fiscalyear') User = Model.get('res.user') companies = Company.find([]) fiscal_years = FiscalYear.find([('state', '=', 'open')]) print( "It will reconcile %d companies and %d years. Do you want to " "continue? [yN]" % (len(companies), len(fiscal_years))) confirmation = sys.stdin.read(1) if confirmation != "y": return user = User(config.user) original_company = user.main_company for company in companies: print " - Reconcile company %s" % (company.rec_name) user.main_company = company user.save() config._context = User.get_preferences(True, config.context) for fiscal_year in FiscalYear.find([ ('company', '=', company.id), ('state', '=', 'open'), ]): for max_lines in (2, 3, 4): print " - Reconcile year %s using %s lines" % ( fiscal_year.name, max_lines) automatic_reconcile = Wizard('account.move_reconcile') assert automatic_reconcile.form.company == company, \ 'Unexpected company "%s" (%s)' % ( automatic_reconcile.form.company, company) # get accounts and parties field to avoid # "Model has no attribute 'accounts'" error automatic_reconcile.form.accounts automatic_reconcile.form.parties automatic_reconcile.form.max_lines = str(max_lines) automatic_reconcile.form.max_months = 12 automatic_reconcile.form.start_date = fiscal_year.start_date automatic_reconcile.form.end_date = fiscal_year.end_date automatic_reconcile.execute('reconcile') user.main_company = original_company user.save()
def test_translation_export(self): Lang = Model.get('ir.lang') Module = Model.get('ir.module.module') translation_export = Wizard('ir.translation.export') translation_export.form.language, = Lang.find([('code', '=', 'en_US')]) translation_export.form.module, = Module.find([('name', '=', 'ir')]) translation_export.execute('export') self.assert_(translation_export.form.file) translation_export.execute('end')
def InitUser(): Module = Model.get('ir.module.module') #party (res, ) = Module.find([('name', '=', 'res')]) Module.install([res.id], config.context) Wizard('ir.module.module.install_upgrade').execute('upgrade') (ir, ) = Module.find([('name', '=', 'ir')]) Module.install([ir.id], config.context) Wizard('ir.module.module.install_upgrade').execute('upgrade')
def create_chart(company=None, config=None): "Create chart of accounts" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') return create_chart
def upgrade_modules(config, modules=None, all=False): ''' Function get from tryton_demo.py in tryton-tools repo: http://hg.tryton.org/tryton-tools ''' assert all or modules Module = Model.get('ir.module.module') if all: modules = Module.find([ ('state', '=', 'installed'), ]) else: modules = Module.find([ ('name', 'in', modules), ('state', '=', 'installed'), ]) Module.upgrade([x.id for x in modules], config.context) Wizard('ir.module.module.install_upgrade').execute('upgrade') ConfigWizardItem = Model.get('ir.module.module.config_wizard.item') for item in ConfigWizardItem.find([('state', '!=', 'done')]): item.state = 'done' item.save() upgraded_modules = [ x.name for x in Module.find([ ('state', '=', 'to_upgrade'), ]) ] return upgraded_modules
def install_modules(config, modules): ''' Function get from tryton_demo.py in tryton-tools repo: http://hg.tryton.org/tryton-tools ''' Module = Model.get('ir.module.module') modules = Module.find([ ('name', 'in', modules), #('state', '!=', 'installed'), ]) Module.install([x.id for x in modules], config.context) modules = [ x.name for x in Module.find([ ('state', 'in', ('to install', 'to_upgrade')), ]) ] Wizard('ir.module.module.install_upgrade').execute('upgrade') ConfigWizardItem = Model.get('ir.module.module.config_wizard.item') for item in ConfigWizardItem.find([('state', '!=', 'done')]): item.state = 'done' item.save() installed_modules = [ m.name for m in Module.find([('state', '=', 'installed')]) ] return modules, installed_modules
def install_modules(): print u'\n>>> instalando modulos...' Module = Model.get('ir.module.module') modules_to_install=[ 'account_ar', 'account_voucher_ar', 'account_check_ar', 'account_bank_ar', 'account_retencion_ar', 'account_coop_ar', 'company_logo', 'account_invoice_ar', ] modules = Module.find([ ('name', 'in', modules_to_install), ]) for module in modules: module.click('install') Wizard('ir.module.module.install_upgrade').execute('upgrade') print u'\n>>> wizards de configuracion se marcan como done...' ConfigWizardItem = Model.get('ir.module.module.config_wizard.item') for item in ConfigWizardItem.find([('state', '!=', 'done')]): item.state = 'done' item.save()
def create_chart(company=None, config=None): """Create chart of accounts""" AccountTemplate = Model.get('account.account.template', config=config) ModelData = Model.get('ir.model.data') AccountChart = Model.get('account.account', config=config) existing_chart = AccountChart.find([('name', '=', CHART_OF_ACCOUNT_NAME)], limit=1) if existing_chart: print("Warning: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' already exists!") return existing_chart[0] if not company: company = get_company() data, = ModelData.find([ ('module', '=', 'account'), ('fs_id', '=', 'account_template_root_en'), ], limit=1) account_template = AccountTemplate(data.db_id) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') print("Success: Account Chart '" + CHART_OF_ACCOUNT_NAME + "' created!") return create_chart
def pay_bill(self, id): """ Makes the payment of the bill :id: the id of the bill :return:boolean True if the value is saved """ newid = id try: invoice = self.Invoice(id=newid) if 'aid' not in invoice.state: #check if paid invoice.click('post') pay = Wizard('account.invoice.pay', [invoice]) pay.form.journal = self.cash_journal pay.execute('choice') invoice.reload() return invoice.state except Exception: if settings.level == 10: logger.exception('raised exception') return False
def setup_company(config): Party = Model.get('party.party') Company = Model.get('company.company') Currency = Model.get('currency.currency') Country = Model.get('country.country') ars, = Currency.find([('code', '=', 'ARS')]) ar, = Country.find([('code', '=', 'AR')]) company_config = Wizard('company.company.config') company_config.execute('company') company = company_config.form party = Party(name='Union Papelera Platense') party.vat_number = '30709170046' party.iva_condition = 'responsable_inscripto' party.save() company.party = party company.currency = ars company_config.execute('add') # Reload context User = Model.get('res.user') config._context = User.get_preferences(True, config.context) company, = Company.find() return company
def setup_company(config): Party = Model.get('party.party') Company = Model.get('company.company') Currency = Model.get('currency.currency') Country = Model.get('country.country') ars, = Currency.find([('code', '=', 'ARS')]) rate = ars.rates.new() rate.date = datetime.date(TODAY.year, 1, 1) rate.rate = Decimal('44.30') ars.save() ar, = Country.find([('code', '=', 'AR')]) company_config = Wizard('company.company.config') company_config.execute('company') company = company_config.form party = Party(name='Cooperativa de Trabajo La Metalurgica LTDA') party.vat_number = '30710288565' party.iva_condition = 'responsable_inscripto' party.save() company.party = party company.currency = ars company_config.execute('add') # Reload context User = Model.get('res.user') config._context = User.get_preferences(True, {}) company, = Company.find() return company
def LoadPlanNIIF(): AccountC = Model.get('account.create_chart.account') Company = Model.get('company.company') empresa = '1191758435001' Template = Model.get('account.account.template') Account = Model.get('account.account') account = Account() account_template = Template.find([('name', '=', 'PLAN DE CUENTAS NIIF ECUADOR'), ('parent', '=', None)]) if len(account_template) == 1: account_t, = account_template account_template = account_t if len(Company.find([('party.vat_number', '=', empresa)])) == 1: company, = Company.find([('party.vat_number', '=', empresa)]) company = company create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') print "Created chart account"
def InitDatabase(): Module = Model.get('ir.module.module') inicio = 4 for i in range(inicio - 1): modules.next() for index, row in enumerate(modules): print row[0] name = row[0] (module, ) = Module.find([('name', '=', name)]) Module.install([module.id], config.context) Wizard('ir.module.module.install_upgrade').execute('upgrade')
def create_chart_of_accounts(config, module, fs_id, company, digits=None, receivable_code=None, payable_code=None): AccountTemplate = Model.get('account.account.template') Account = Model.get('account.account') ModelData = Model.get('ir.model.data') root_accounts = Account.find([('parent', '=', None)]) if root_accounts: return data = ModelData.find([('module', '=', module), ('fs_id', '=', fs_id)], limit=1) assert len(data) == 1, ('Unexpected num of root templates ' 'with name "%s": %s' % (module, fs_id)) account_template = data[0].db_id create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = AccountTemplate(account_template) create_chart.form.company = company create_chart.form.account_code_digits = digits create_chart.execute('create_account') receivable_domain = [ ('kind', '=', 'receivable'), ('company', '=', company.id), ] if receivable_code is not None: receivable_domain.append(('code', '=', receivable_code)) receivable = Account.find(receivable_domain) receivable = receivable[0] payable_domain = [ ('kind', '=', 'payable'), ('company', '=', company.id), ] if payable_code is not None: payable_domain.append(('code', '=', payable_code)) payable = Account.find(payable_domain)[0] create_chart.form.account_receivable = receivable create_chart.form.account_payable = payable create_chart.execute('create_properties')
def test_user_config(self): User = Model.get('res.user') user_config = Wizard('res.user.config') user_config.execute('user') user_config.form.name = 'Foo' user_config.form.login = '******' user_config.execute('add') self.assertEqual(user_config.form.name, None) self.assertEqual(user_config.form.login, None) user_config.form.name = 'Bar' user_config.form.login = '******' user_config.execute('end') self.assertTrue(User.find([('name', '=', 'Foo')])) self.assertFalse(User.find([('name', '=', 'Bar')]))
def activate_modules(self, activate_modules): Module = Model.get('ir.module') available_modules = Module.find([('name', 'in', activate_modules)]) missing_modules = (set(activate_modules) - set([m.name for m in available_modules])) if missing_modules: logger.warning("some trytond modules are not available for " "activation: {missing_modules}".format( missing_modules=missing_modules)) for module in available_modules: module.click('activate') Wizard('ir.module.activate_upgrade').execute('upgrade')
def test_translation_export(self): Lang = Model.get('ir.lang') Module = Model.get('ir.module') translation_export = Wizard('ir.translation.export') translation_export.form.language, = Lang.find([('code', '=', 'en')]) translation_export.form.module, = Module.find([('name', '=', 'ir')]) translation_export.execute('export') self.assertTrue(translation_export.form.file) translation_export.execute('end')
def setup_languages(config, modules, demo_password, company=None): Lang = Model.get('ir.lang') Module = Model.get('ir.module') User = Model.get('res.user') Group = Model.get('res.group') Action = Model.get('ir.action') langs = Lang.find([('code', '=', 'es')]) Lang.write([x.id for x in langs], { 'translatable': True, }, config.context) Module.upgrade([x.id for x in Module.find([('name', 'in', modules)])], config.context) Wizard('ir.module.activate_upgrade').execute('upgrade') admin = config.user # Use root to skip password validation config.user = 0 menu, = Action.find([('usage', '=', 'menu')]) for lang in langs: if lang.code == 'en': name = 'Demo' login = '******' else: if lang.code[:2] != lang.code[-2:].lower(): continue name = 'Demo %s' % lang.name login = '******' % lang.code[:2] try: user, = User.find([('login', '=', login)]) except ValueError: user = User() user.name = name user.login = login user.password = demo_password groups = Group.find([ ('name', 'not ilike', '%Admin%'), ]) user.groups.extend(groups) user.language = lang user.menu = menu if company: user.main_company = company user.company = company user.save() config.user = admin
def test_user_config(self): User = Model.get('res.user') user_config = Wizard('res.user.config') user_config.execute('user') user_config.form.name = 'Foo' user_config.form.login = '******' user_config.execute('add') self.assertEqual(user_config.form.name, None) self.assertEqual(user_config.form.login, None) user_config.form.name = 'Bar' user_config.form.login = '******' user_config.execute('end') self.assert_(User.find([('name', '=', 'Foo')])) self.assertFalse(User.find([('name', '=', 'Bar')]))
def activate_modules(modules, cache_file_name=None): if isinstance(modules, basestring): modules = [modules] cache_name = cache_file_name or '-'.join(modules) if restore_db_cache(cache_name): return _get_config() drop_create() cfg = _get_config() Module = Model.get('ir.module') records = Module.find([ ('name', 'in', modules), ]) assert len(records) == len(modules) Module.click(records, 'activate') Wizard('ir.module.activate_upgrade').execute('upgrade') backup_db_cache(cache_name) return cfg
def install_modules(modules): if isinstance(modules, basestring): modules = [modules] cache_name = '-'.join(modules) if restore_db_cache(cache_name): return _get_config() drop_create() cfg = _get_config() Module = Model.get('ir.module') modules = Module.find([ ('name', 'in', modules), ]) Module.click(modules, 'install') Wizard('ir.module.install_upgrade').execute('upgrade') backup_db_cache(cache_name) return cfg
def install_modules(config, modules): Module = Model.get('ir.module.module') modules = Module.find([ ('name', 'in', modules), ('state', '!=', 'installed'), ]) Module.install([x.id for x in modules], config.context) modules = [x.name for x in Module.find([('state', '=', 'to install')])] Wizard('ir.module.module.install_upgrade').execute('upgrade') ConfigWizardItem = Model.get('ir.module.module.config_wizard.item') for item in ConfigWizardItem.find([('state', '!=', 'done')]): item.state = 'done' item.save() installed_modules = [ m.name for m in Module.find([('state', '=', 'installed')]) ] return modules, installed_modules
def create_chart(company=None, config=None): "Create chart of accounts" AccountTemplate = Model.get('account.account.template', config=config) if not company: company = get_company() account_template, = AccountTemplate.find([('parent', '=', None)]) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') accounts = get_accounts(company, config=config) create_chart.form.account_receivable = accounts['receivable'] create_chart.form.account_payable = accounts['payable'] create_chart.execute('create_properties') return create_chart
def activate_modules(modules): if isinstance(modules, basestring): modules = [modules] cache_name = '-'.join(modules) # JCA : restore_db_cache fails if the database already exists drop_db() if restore_db_cache(cache_name): return _get_config() create_db() cfg = _get_config() Module = Model.get('ir.module') modules = Module.find([ ('name', 'in', modules), ]) Module.click(modules, 'activate') Wizard('ir.module.activate_upgrade').execute('upgrade') backup_db_cache(cache_name) return cfg
def setup_account_payment(config, modules, company): Currency = Model.get('currency.currency') Journal = Model.get('account.payment.journal') Line = Model.get('account.move.line') Payment = Model.get('account.payment') usd, = Currency.find([('code', '=', 'USD')]) journal = Journal(name='Manual', currency=usd, company=company, process_method='manual') journal.save() lines = Line.find([ ('account.kind', '=', 'payable'), ('party', '!=', None), ('reconciliation', '=', None), ('payment_amount', '!=', 0), ]) lines = random.sample(lines, len(lines) * 2 // 3) if not lines: return pay_line = Wizard('account.move.line.pay', lines) pay_line.form.journal = journal pay_line.execute('start') payments = Payment.find([]) payments = random.sample(payments, len(payments) * 2 // 3) for payment in payments: payment.click('approve') payments = random.sample(payments, len(payments) * 2 // 3) i = j = 0 while i < len(payments): j = random.randint(1, 5) process = Wizard('account.payment.process', payments[i:i + j]) process.execute('process') i += j
def activate_modules(config, modules): Module = Model.get('ir.module') modules = Module.find([ ('name', 'in', modules), ]) for module in modules: if module.state == 'activated': module.click('upgrade') else: module.click('activate') modules = [x.name for x 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 uninstall_task(database, modules, config_file=os.environ.get('TRYTOND_CONFIG')): """ Uninstall the supplied modules (separated by coma) from database. """ if not database or not modules: return if isinstance(modules, basestring): modules = modules.replace(" ", "").split(',') if not modules: return print t.bold("uninstall: ") + ", ".join(modules) if not check_database(database, {}): return config = pconfig.set_trytond(database=database, config_file=config_file) if proteus_version < '3.5': Module = Model.get('ir.module.module') else: Module = Model.get('ir.module') modules_to_uninstall = Module.find([('name', 'in', modules), ('state', '=', 'installed')]) Module.uninstall([m.id for m in modules_to_uninstall], config.context) if proteus_version < '3.5': module_install_upgrade = Wizard('ir.module.module.install_upgrade') else: module_install_upgrade = Wizard('ir.module.install_upgrade') module_install_upgrade.execute('upgrade') module_install_upgrade.execute('config') print ""
def create_company(config, name, street=None, zip=None, city=None, subdivision_code=None, country_code='ES', currency_code='EUR', phone=None, website=None): ''' Based on tryton_demo.py in tryton-tools repo: http://hg.tryton.org/tryton-tools ''' Company = Model.get('company.company') Currency = Model.get('currency.currency') party = create_party(config, name, street=street, zip=zip, city=city, subdivision_code=subdivision_code, country_code=country_code, phone=phone, website=website) companies = Company.find([('party', '=', party.id)]) if companies: return companies[0] currency, = Currency.find([('code', '=', currency_code)]) company_config = Wizard('company.company.config') company_config.execute('company') company = company_config.form company.party = party company.currency = currency company_config.execute('add') # Reload context User = Model.get('res.user') config._context = User.get_preferences(True, config.context) company, = Company.find([('party', '=', party.id)]) return company
def create_company(party=None, currency=None, config=None): "Create the company using the proteus config" Party = Model.get('party.party', config=config) User = Model.get('res.user', config=config) company_config = Wizard('company.company.config') company_config.execute('company') company = company_config.form if not party: party = Party(name='Dunder Mifflin') party.save() company.party = party if not currency: currency = get_currency() company.currency = currency company_config.execute('add') if not config: config = get_config() config._context = User.get_preferences(True, {}) return company_config
def crear_scenario_tipo(config, lang): """ Crear el scenario base """ Company = Model.get('company.company') User = Model.get('res.user') company, = Company.find([]) # reload the context print u'\n>>> creando admin...' config._context = User.get_preferences(True, config.context) admin_user = User.find()[0] admin_user.password = '******' admin_user.main_company = company admin_user.language = lang admin_user.save() # create fiscal year: print u'\n>>> creando fiscal actual...' FiscalYear = Model.get('account.fiscalyear') Sequence = Model.get('ir.sequence') SequenceStrict = Model.get('ir.sequence.strict') fiscalyear = FiscalYear(name=str(today.year)) fiscalyear.start_date = today + relativedelta(month=1, day=1) fiscalyear.end_date = today + relativedelta(month=12, day=31) fiscalyear.company = company post_move_seq = Sequence(name=str(today.year), code='account.move', company=company) post_move_seq.save() fiscalyear.post_move_sequence = post_move_seq invoice_seq = SequenceStrict(name=str(today.year), code='account.invoice', company=company) invoice_seq.save() fiscalyear.out_invoice_sequence = invoice_seq fiscalyear.in_invoice_sequence = invoice_seq fiscalyear.out_credit_note_sequence = invoice_seq fiscalyear.in_credit_note_sequence = invoice_seq fiscalyear.save() FiscalYear.create_period([fiscalyear.id], config.context) ## create chart of accounts:: print u'\n>>> creando cuentas...' AccountTemplate = Model.get('account.account.template') Account = Model.get('account.account') Journal = Model.get('account.journal') account_template, = AccountTemplate.find( [('parent', '=', None), ('name', '=', 'Plan Contable Argentino para Cooperativas')] ) create_chart = Wizard('account.create_chart') create_chart.execute('account') create_chart.form.account_template = account_template create_chart.form.company = company create_chart.execute('create_account') receivable, = Account.find([ ('kind', '=', 'receivable'), ('code', '=', '1131'), # Deudores por servicios ('company', '=', company.id), ]) payable, = Account.find([ ('kind', '=', 'payable'), ('code', '=', '2111'), # Proveedores ('company', '=', company.id), ]) revenue, = Account.find([ ('kind', '=', 'revenue'), ('code', '=', '511'), # Ingresos por servicios realizados ('company', '=', company.id), ]) expense, = Account.find([ ('kind', '=', 'expense'), ('code', '=', '5249'), # Gastos Varios ('company', '=', company.id), ]) #receivable, = Account.find([ # ('kind', '=', 'receivable'), # ('code', '=', '11301'), # deudores por venta # ('company', '=', company.id), # ]) #payable, = Account.find([ # ('kind', '=', 'payable'), # ('code', '=', '21301'), # proveedores # ('company', '=', company.id), # ]) #revenue, = Account.find([ # ('kind', '=', 'revenue'), # ('code', '=', '41100'), # ingresos por venta # ('company', '=', company.id), # ]) #expense, = Account.find([ # ('kind', '=', 'expense'), # ('code', '=', '5119'), # gastos operativos en general # ('company', '=', company.id), # ]) create_chart.form.account_receivable = receivable create_chart.form.account_payable = payable create_chart.execute('create_properties') cash, = Account.find([ ('kind', '=', 'stock'), ('name', '=', 'Caja'), ('code', '=', '1111'), ('company', '=', company.id), ]) #cash, = Account.find([ # ('kind', '=', 'other'), # ('name', '=', 'Caja pesos'), # ('code', '=', '11101'), # ('company', '=', company.id), # ]) cash_journal, = Journal.find([('type', '=', 'cash')]) cash_journal.credit_account = cash cash_journal.debit_account = cash cash_journal.save() ## create payment term: print u'\n>>> creando terminos de pago...' PaymentTerm = Model.get('account.invoice.payment_term') PaymentTermLine = Model.get('account.invoice.payment_term.line') print u'\n>>> creando termino de pago 30 dias...' payment_term = PaymentTerm(name=u'30 días') payment_term_line = PaymentTermLine(type='remainder', days=30) payment_term.lines.append(payment_term_line) payment_term.save() print u'\n>>> creando termino de pago 60 dias...' payment_term = PaymentTerm(name=u'60 días') payment_term_line = PaymentTermLine(type='remainder', days=60) payment_term.lines.append(payment_term_line) payment_term.save() print u'\n>>> creando termino de pago Efectivo...' payment_term = PaymentTerm(name='Contado') payment_term_line = PaymentTermLine(type='remainder', days=0) payment_term.lines.append(payment_term_line) payment_term.save() # instalo modulo stock print u'\n>>> instalando stock...' Module = Model.get('ir.module.module') module, = Module.find([('name', '=', 'stock')]) module.click('install') Wizard('ir.module.module.install_upgrade').execute('upgrade') config.user = admin_user.id Inventory = Model.get('stock.inventory') Location = Model.get('stock.location') storage, = Location.find([ ('code', '=', 'STO'), ]) inventory = Inventory() inventory.location = storage inventory.save() PartyConfig = Model.get('party.configuration') print u'\n>>> Idioma de la entidad por defecto es Spanish Argentina...' party_config = PartyConfig([]) party_config.party_lang = lang party_config.save() print u'\n>>> Comienza configuracion_contable...' AccountConfiguration = Model.get('account.configuration') Account = Model.get('account.account') account_config, = AccountConfiguration.find([]) account_config.default_account_receivable = receivable account_config.default_account_payable = payable account_config.save() print u'\n>>> scenario base done.'
def step_impl(context): config = context.oProteusConfig Party = proteus.Model.get('party.party') Company = proteus.Model.get('company.company') sCompanyName = sGetFeatureData(context, 'party,company_name') party, = Party.find([('name', '=', sCompanyName)]) company, = Company.find([('party.id', '=', party.id)]) FiscalYear = proteus.Model.get('account.fiscalyear') fiscalyear, = FiscalYear.find([('name', '=', str(TODAY.year))]) period = fiscalyear.periods[0] Account = proteus.Model.get('account.account') receivable, = Account.find([ ('kind', '=', 'receivable'), ('name', '=', sGetFeatureData(context, 'account.template,main_receivable')), ('company', '=', company.id), ]) revenue, = Account.find([ ('kind', '=', 'revenue'), ('name', '=', sGetFeatureData(context, 'account.template,main_revenue')), ('company', '=', company.id), ]) asset_account = Account.find([ #expense ('kind', '=', 'other'), ('name', '=', sGetFeatureData(context, 'account.template,main_asset')), ('company', '=', company.id), ]) # Tangible assets depn depreciation_account, = Account.find([ ('kind', '=', 'other'), ('company', '=', company.id), ('name', '=', sGetFeatureData(context, 'account.template,main_depreciation')), ]) expense, = Account.find([ ('kind', '=', 'expense'), ('name', '=', sGetFeatureData(context, 'account.template,main_expense')), ('company', '=', company.id), ]) ProductUom = Model.get('product.uom') unit, = ProductUom.find([('name', '=', 'Unit')]) ProductTemplate = Model.get('product.template') Product = Model.get('product.product') asset_product = Product() asset_template = ProductTemplate() asset_template.name = 'Asset' asset_template.type = 'assets' asset_template.default_uom = unit asset_template.list_price = Decimal('1000') asset_template.cost_price = Decimal('1000') asset_template.depreciable = True asset_template.account_expense = expense asset_template.account_revenue = revenue asset_template.account_asset = asset_account asset_template.account_depreciation = depreciation_account asset_template.depreciation_duration = Decimal(24) asset_template.save() asset_product.template = asset_template asset_product.save() #@step('Create supplier') #def step_impl(context): Party = Model.get('party.party') supplier = Party(name='Supplier') supplier.save() customer = Party(name='Customer') customer.save() #@step('Create payment term') #def step_impl(context): payment_term = create_payment_term() payment_term.save() #@step('Buy an asset') #def step_impl(context): Invoice = Model.get('account.invoice') InvoiceLine = Model.get('account.invoice.line') supplier_invoice = Invoice(type='in_invoice') supplier_invoice.party = supplier invoice_line = InvoiceLine() supplier_invoice.lines.append(invoice_line) invoice_line.product = asset_product invoice_line.quantity = 1 assert invoice_line.account == asset_account supplier_invoice.invoice_date = TODAY + relativedelta(day=1, month=1) supplier_invoice.click('post') assert supplier_invoice.state == u'posted' invoice_line, = supplier_invoice.lines assert (asset_account.debit, asset_account.credit) == \ (Decimal('1000'), Decimal('0')) #@step('Depreciate the asset') #def step_impl(context) Asset = Model.get('account.asset') asset = Asset() asset.depreciation_method = 'linear' asset.frequency = 'monthly' # comment asset.product = asset_product asset.supplier_invoice_line = invoice_line assert asset.value == Decimal('1000.00') assert asset.start_date == supplier_invoice.invoice_date assert asset.end_date == (supplier_invoice.invoice_date + \ relativedelta(years=2, days=-1)) assert asset.quantity == 1.0 assert asset.unit == unit asset.residual_value = Decimal('100') asset.click('create_lines') assert len(asset.lines) == 24 assert [l.depreciation for l in asset.lines] == [Decimal('37.5')] * 24 assert asset.lines[0].actual_value == Decimal('962.50') assert asset.lines[0].accumulated_depreciation == Decimal('37.50') assert asset.lines[11].actual_value == Decimal('550.00') assert asset.lines[11].accumulated_depreciation == Decimal('450.00') assert asset.lines[-1].actual_value == Decimal('100.00') assert asset.lines[-1].accumulated_depreciation == Decimal('900.00') asset.click('run') #@step('Create Moves for 3 months') #def step_impl(context): create_moves = Wizard('account.asset.create_moves') create_moves.form.date = (supplier_invoice.invoice_date \ + relativedelta(months=3)) create_moves.execute('create_moves') assert depreciation_account.debit == Decimal('0.00') assert depreciation_account.credit == Decimal('112.50') assert expense.debit == Decimal('112.50') assert expense.credit == Decimal('0.00') #@step('Update the asset') #def step_impl(context): update = Wizard('account.asset.update', [asset]) update.form.value = Decimal('1100') update.execute('update_asset') assert update.form.amount == Decimal('100.00') update.form.date = (supplier_invoice.invoice_date \ + relativedelta(months=2)) assert update.form.latest_move_date == (supplier_invoice.invoice_date \ + relativedelta(months=3, days=-1)) assert update.form.next_depreciation_date == (supplier_invoice.invoice_date \ + relativedelta(months=4, days=-1)) try: update.execute('create_move') except ValueError: pass else: raise RuntimeError('A ValueError should have been raised') update.form.date = (supplier_invoice.invoice_date \ + relativedelta(months=3)) update.execute('create_move') asset.reload() assert asset.value == Decimal('1100') assert [l.depreciation for l in asset.lines[:3]] == \ [Decimal('37.50'), Decimal('37.50'), Decimal('37.50')] assert [l.depreciation for l in asset.lines[3:-1]] == \ [Decimal('42.26')] * 20 assert asset.lines[-1].depreciation == Decimal('42.30') depreciation_account.reload() assert depreciation_account.debit == Decimal('100.00') assert depreciation_account.credit == Decimal('112.50') expense.reload() assert expense.debit == Decimal('112.50') assert expense.credit == Decimal('100.00') #@step('Create Moves for 3 other months') #def step_impl(context): create_moves = Wizard('account.asset.create_moves') create_moves.form.date = (supplier_invoice.invoice_date + relativedelta(months=6)) create_moves.execute('create_moves') depreciation_account.reload() assert depreciation_account.debit == Decimal('100.00') assert depreciation_account.credit == Decimal('239.28') expense.reload() assert expense.debit == Decimal('239.28') assert expense.credit == Decimal('100.00') #@step('Sale the asset') #def step_impl(context): customer_invoice = Invoice(type='out_invoice') customer_invoice.party = customer invoice_line = InvoiceLine() customer_invoice.lines.append(invoice_line) invoice_line.product = asset_product invoice_line.asset = asset invoice_line.quantity = 1 invoice_line.unit_price = Decimal('600') assert invoice_line.account == revenue customer_invoice.click('post') assert customer_invoice.state == u'posted' asset.reload() assert asset.customer_invoice_line == customer_invoice.lines[0] assert revenue.debit == Decimal('860.72') assert revenue.credit == Decimal('600.00') asset_account.reload() assert asset_account.debit == Decimal('1000.00') assert asset_account.credit == Decimal('1100.00') depreciation_account.reload() assert depreciation_account.debit == Decimal('339.28') assert depreciation_account.credit == Decimal('239.28')
def test_translation_update(self): print_model_graph = Wizard('ir.translation.update') self.assertEqual(len(print_model_graph.actions), 0) print_model_graph.execute('update') self.assertEqual(len(print_model_graph.actions), 1)
def test_configuration_wizard(self): config_wizard = Wizard('ir.module.config_wizard') config_wizard.execute('action') self.assertTrue(config_wizard.actions)