예제 #1
0
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))
예제 #2
0
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"
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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')
예제 #6
0
 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')
예제 #7
0
 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')
예제 #8
0
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()
예제 #9
0
 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')
예제 #10
0
 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')
예제 #11
0
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
예제 #12
0
def prepare_translations(ctx,
                         database,
                         langs=None,
                         host=None,
                         port=None,
                         dbuser=None,
                         dbpassword=None,
                         config_file=os.environ.get('TRYTOND_CONFIG')):
    """
    Runs the set, clean and update translations wizards in the given database.
    """
    print(
        t.bold('prepare_translations: database=%s, langs=%s') %
        (database, langs))
    if not _check_database(database, host, port, dbuser, dbpassword):
        return

    config.set_trytond(database=database, config_file=config_file)

    Lang = Model.get('ir.lang')
    if langs is None:
        languages = Lang.find([
            ('translatable', '=', True),
        ])
    else:
        langs = langs.split(',')
        languages = Lang.find([
            ('code', 'in', langs),
        ])
        if set(langs) != set(l.code for l in languages):
            print(t.bold('Invalid languages: %s') % languages)
            return

    translation_set = Wizard('ir.translation.set')
    translation_set.execute('set_')
    translation_set.execute('end')

    translation_clean = Wizard('ir.translation.clean')
    translation_clean.execute('clean')
    translation_clean.execute('end')

    for language in languages:
        translation_update = Wizard('ir.translation.update')
        translation_update.form.language = language
        translation_update.execute('update')
        print("%s translation updated" % language.name)
예제 #13
0
 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
예제 #14
0
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
예제 #15
0
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
예제 #16
0
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
예제 #17
0
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
예제 #18
0
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
예제 #19
0
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 ""
예제 #20
0
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')
예제 #21
0
    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')]))
예제 #22
0
    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')]))
예제 #23
0
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
예제 #24
0
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
예제 #25
0
def load_bank_es():
    'Loads all banks from spain'
    load_banks = Wizard('load.banks')
    load_banks.execute('accept')
예제 #26
0
        modules = Module.find([
            ('state', '=', 'installed'),
            ('name', '=', settings.module),
        ])

    Lang = Model.get('ir.lang')
    language, = Lang.find([('code', '=', settings.lang)])

    for module in modules:
        path = settings.path if settings.path else ''
        path = os.path.join(path, dest_path % module.name)
        if not os.path.exists(path):
            path = settings.path if settings.path else ''
            path = os.path.join(path, module.name, 'locale')
            if not os.path.exists(path):
                print 'Path \'%s\' not found.' % path
                continue
        translation_export = Wizard('ir.translation.export')
        translation_export.form.language = language
        translation_export.form.module = module
        translation_export.execute('export')
        if not translation_export.form.file:
            continue
        path = path + '/%s.po' % language.code
        f = open(path, 'w')
        try:
            f.write(str(translation_export.form.file))
        finally:
            f.close()
        print 'Module \'%s\' exported successfully.' % module.name
예제 #27
0
 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)
예제 #28
0
def setup_account(config, modules, company):
    AccountTemplate = Model.get('account.account.template')
    Account = Model.get('account.account')
    FiscalYear = Model.get('account.fiscalyear')
    Sequence = Model.get('ir.sequence')
    SequenceStrict = Model.get('ir.sequence.strict')
    Party = Model.get('party.party')

    root_template, = AccountTemplate.find([
        ('parent', '=', None),
        ('name', '=', 'Plan Contable Argentino'),
    ])
    create_chart_account = Wizard('account.create_chart')
    create_chart_account.execute('account')
    create_chart_account.form.account_template = root_template
    create_chart_account.form.company = company
    create_chart_account.execute('create_account')

    receivable, = Account.find([
        ('kind', '=', 'receivable'),
        ('code', '=', '11301'),  # Deudores por ventas
        ('company', '=', company.id),
    ])
    payable, = Account.find([
        ('kind', '=', 'payable'),
        ('code', '=', '21301'),  # Proveedores
        ('company', '=', company.id),
    ])

    create_chart_account.form.account_receivable = receivable
    create_chart_account.form.account_payable = payable
    create_chart_account.execute('create_properties')

    # Set account for parties created without company
    parties = Party.find([])
    for party in parties:
        party.account_receivable = receivable
        party.account_payable = payable
    Party.save(parties)

    for start_date in (TODAY + relativedelta(month=1, day=1, years=-1),
                       TODAY + relativedelta(month=1, day=1),
                       TODAY + relativedelta(month=1, day=1, years=1)):
        fiscalyear = FiscalYear(name='%s' % start_date.year)
        fiscalyear.start_date = start_date
        fiscalyear.end_date = start_date + relativedelta(month=12, day=31)
        fiscalyear.company = company
        post_move_sequence = Sequence(name='%s' % start_date.year,
                                      code='account.move',
                                      company=company)
        post_move_sequence.save()
        fiscalyear.post_move_sequence = post_move_sequence
        invoice_sequence, = fiscalyear.invoice_sequences
        if 'account_invoice' in modules:
            for attr, name in (('out_invoice_sequence', 'Invoice'),
                               ('in_invoice_sequence', 'Supplier Invoice'),
                               ('out_credit_note_sequence',
                                'Credit Note'), ('in_credit_note_sequence',
                                                 'Supplier Credit Note')):
                sequence = SequenceStrict(name='%s %s' %
                                          (name, start_date.year),
                                          code='account.invoice',
                                          company=company)
                sequence.save()
                setattr(invoice_sequence, attr, sequence)
        if 'account_voucher_ar' in modules:
            sequence = Sequence(name='%s %s' %
                                ('Recibo de Pago', start_date.year),
                                code='account.voucher.payment',
                                company=company)
            sequence.save()
            setattr(fiscalyear, 'payment_sequence', sequence)
            sequence = Sequence(name='%s %s' %
                                ('Recibo de Cobro', start_date.year),
                                code='account.voucher.receipt',
                                company=company)
            sequence.save()
            setattr(fiscalyear, 'receipt_sequence', sequence)
        if 'cooperative_ar' in modules:
            sequence = Sequence(
                name='%s %s' %
                ('Recibo comprobante cooperativa', start_date.year),
                code='account.cooperative.receipt',
                company=company)
            sequence.save()
            setattr(fiscalyear, 'cooperative_receipt_sequence', sequence)
        fiscalyear.save()
        FiscalYear.create_period([fiscalyear.id], config.context)
예제 #29
0
 def test_configuration_wizard(self):
     config_wizard = Wizard('ir.module.config_wizard')
     config_wizard.execute('action')
     self.assertTrue(config_wizard.actions)
예제 #30
0
def export_translations(database,
                        modules,
                        langs=None,
                        host=None,
                        port=None,
                        dbuser=None,
                        dbpassword=None,
                        config_file=os.environ.get('TRYTOND_CONFIG')):
    """
    Creates translation files for the given modules and the specified languages.

    If no languages are specified, the ones marked as translatable in the
    database are used.
    """
    print t.bold('export_translations: %s, %s, %s') % (database, modules,
                                                       langs)
    if not _check_database(database, host, port, dbuser, dbpassword):
        return

    config.set_trytond(database=database, config_file=config_file)

    try:
        Module = Model.get('ir.module')
    except KeyError:
        # Compatibility with versions older than 3.8
        Module = Model.get('ir.module.module')
    if modules == 'all':
        ir_modules = Module.find([
            ('state', '=', 'installed'),
        ])
    else:
        modules = modules.split(',')
        ir_modules = Module.find([
            ('state', '=', 'installed'),
            ('name', 'in', modules),
        ])
        missing_modules = set(modules) - set(m.name for m in ir_modules)
        if missing_modules:
            print t.bold('Invalid modules: %s') % missing_modules
            return

    Lang = Model.get('ir.lang')
    if langs is None:
        languages = Lang.find([
            ('translatable', '=', True),
        ])
    else:
        langs = langs.split(',')
        languages = Lang.find([
            ('code', 'in', langs),
        ])
        if set(langs) != set(l.code for l in languages):
            print 'Invalid languages: %s' % languages
            return

    for module in ir_modules:
        module_locale_path = os.path.abspath(
            os.path.normpath(
                os.path.join(os.getcwd(), 'modules', module.name, 'locale')))
        if not os.path.exists(module_locale_path):
            os.makedirs(module_locale_path)

        for language in languages:
            if language.code == 'en_US':
                continue

            translation_export = Wizard('ir.translation.export')
            translation_export.form.language = language
            translation_export.form.module = module
            translation_export.execute('export')
            if not translation_export.form.file:
                continue

            file_path = os.path.join(module_locale_path,
                                     '%s.po' % language.code)
            with open(file_path, 'w') as f:
                f.write(str(translation_export.form.file))
            translation_export.execute('end')
            print('Translation of "%s" in "%s" exported successfully.' %
                  (module.name, language.code))
예제 #31
0
                             config_file=os.path.join(os.getcwd(), 'FSERP',
                                                      'trytond', 'etc',
                                                      'trytond.conf'))
    Currency = Model.get('currency.currency')
    currencies = Currency.find([('code', '=', 'INR')])
    currency, = currencies

    Party = Model.get('party.party')
    party = Party(id=1)

    company_config = Wizard('company.company.config')
    User = Model.get('res.user')
    Group = Model.get('res.group')
    con._context = User.get_preferences(True, con.context)

    company_config.execute('company')
    company = company_config.form
    company.party = party
    company.currency = currency
    company_config.execute('add')

    con._context = User.get_preferences(True, con.context)
    User = Model.get('res.user')

    user = User(id=con.user)
    company = user.main_company

    Tax = Model.get('account.tax')
    tax = Tax()
    tax.name = 'Tax 11.5%'
    tax.description = tax.name
예제 #32
0
def load_country_zip_es():
    'Loads zip codes from spain'
    load_zips = Wizard('load.country.zips')
    load_zips.execute('accept')
예제 #33
0
 def test_configuration_wizard(self):
     config_wizard = Wizard('ir.module.config_wizard')
     config_wizard.execute('action')
     self.assertTrue(config_wizard.actions)
예제 #34
0
 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 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')
예제 #36
0
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.'