コード例 #1
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def search_groups(names):
    """ Search groups by name and full name """
    names = list(set(names))
    group_full_names = [name for name in names if '/' in name]
    group_single_names = [name for name in names if not '/' in name]
    ModuleCategory = model('ir.module.category')
    groups = []
    if group_full_names:
        full_name_cond = []
        for line in group_full_names:
            categ, name = line.split('/', 1)
            categ = categ.strip()
            name = name.strip()
            category_ids = ModuleCategory.search([('name', '=', categ)])
            assert category_ids, 'no category named %s' % categ
            condition = [
                    '&',
                    ('name', '=', name),
                    ('category_id', 'in', category_ids)
                ]
            full_name_cond += condition
        num_operators = len(group_full_names) - 1
        or_operators = ['|'] * num_operators
        search_cond = or_operators + full_name_cond
        groups.extend(model('res.groups').browse(search_cond))
    if group_single_names:
        single_name_cond = [('name', 'in', group_single_names)]
        # Search for single groups
        groups.extend(model('res.groups').browse(single_name_cond))
    return groups
コード例 #2
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def search_groups(names):
    """ Search groups by name and full name """
    names = list(set(names))
    group_full_names = [name for name in names if '/' in name]
    group_single_names = [name for name in names if not '/' in name]
    ModuleCategory = model('ir.module.category')
    groups = []
    if group_full_names:
        full_name_cond = []
        for line in group_full_names:
            categ, name = line.split('/', 1)
            categ = categ.strip()
            name = name.strip()
            category_ids = ModuleCategory.search([('name', '=', categ)])
            assert category_ids, 'no category named %s' % categ
            condition = [
                '&', ('name', '=', name), ('category_id', 'in', category_ids)
            ]
            full_name_cond += condition
        num_operators = len(group_full_names) - 1
        or_operators = ['|'] * num_operators
        search_cond = or_operators + full_name_cond
        groups.extend(model('res.groups').browse(search_cond))
    if group_single_names:
        single_name_cond = [('name', 'in', group_single_names)]
        # Search for single groups
        groups.extend(model('res.groups').browse(single_name_cond))
    return groups
コード例 #3
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def tag_user_partners(ctx, xmlid):
    model_name, ids = ctx.loaded_objets
    obj = ref(xmlid)
    if model_name == 'res.users':
        partners = model(model_name).browse(ids).partner_id
    elif model_name == 'res.partner':
        partners = model(model_name).browse(ids)
    partners.write({'category_id': [obj.id]})
コード例 #4
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def tag_user_partners(ctx, xmlid):
    model_name, ids = ctx.loaded_objets
    obj = ref(xmlid)
    if model_name == 'res.users':
        partners = model(model_name).browse(ids).partner_id
    elif model_name == 'res.partner':
        partners = model(model_name).browse(ids)
    partners.write({'category_id': [obj.id]})
コード例 #5
0
def impl(ctx, rate_code, rate_value):
    assert ctx.found_item
    company = ctx.found_item
    currency = model('res.currency').get([('name', '=', rate_code)])
    assert currency
    rate = model('res.currency.rate').get([('currency_id', '=', currency.id)])
    assert rate
    rate.write({'rate': rate_value})
    company.write({'currency_id': currency.id})
コード例 #6
0
def impl(ctx, webkit_path):
    key = model('ir.config_parameter').get([('key', '=', "webkit_path")])
    if key:
        key.write({'value': webkit_path})
    else:
        model('ir.config_parameter').create({
            'key': 'webkit_path',
            'value': webkit_path
        })
コード例 #7
0
def impl(ctx, rate_code, rate_value):
    assert ctx.found_item
    company = ctx.found_item
    currency = model("res.currency").get([("name", "=", rate_code)])
    assert currency
    rate = model("res.currency.rate").get([("currency_id", "=", currency.id)])
    assert rate
    rate.write({"rate": rate_value})
    company.write({"currency_id": currency.id})
コード例 #8
0
ファイル: bank_config.py プロジェクト: esciara/oerpscenario
def impl(ctx, field, value, company_name):
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    journal = model('account.journal').get([(field, '=', value), ('company_id', '=', company.id)])
    # if not journal:
    #     import pdb; pdb.set_trace()

    assert journal
    ctx.found_item = journal
    ctx.search_model_name = 'account.journal'
コード例 #9
0
ファイル: bank_config.py プロジェクト: esciara/oerpscenario
def impl(ctx, field, value, company_name):
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    journal = model('account.journal').get([(field, '=', value),
                                            ('company_id', '=', company.id)])
    # if not journal:
    #     import pdb; pdb.set_trace()

    assert journal
    ctx.found_item = journal
    ctx.search_model_name = 'account.journal'
コード例 #10
0
def impl(ctx, logo_name, logo_path):
    cp_id = getattr(ctx, "company_id")

    filename, extension = os.path.splitext(logo_path)
    assert extension.lower() in [".png", ".gif", ".jpeg", ".jpg"], "Image extension must be (.png, .gif or .jpeg)"

    encoded_image = get_encoded_image(ctx, logo_path)

    values = {"img": encoded_image, "name": logo_name, "type": extension[1:], "company_id": cp_id}

    header_img = model("ir.header_img").browse([("name", "=", logo_name), ("company_id", "=", cp_id)])
    if header_img:
        header_img.write(values)
    else:
        model("ir.header_img").create(values)
コード例 #11
0
def impl(ctx, fy_ref):
    """Create monthly periods `account.period` for the given fiscal year
    `account.fiscal.year`

    :param fy_ref: fiscal year code that needs periods
    :type fy_ref: string

    """
    assert '.' in fy_ref, "please use the full reference (e.g. scenario.%s)" % fy_ref
    module, xmlid = fy_ref.split('.', 1)
    _model, id = model('ir.model.data').get_object_reference(module, xmlid)
    assert _model == 'account.fiscalyear'
    fy = model('account.fiscalyear').get(id)
    fy.read('period_ids')
    if not fy.period_ids:
        model('account.fiscalyear').create_period([fy.id], {}, 1)
コード例 #12
0
ファイル: system_params.py プロジェクト: esciara/oerpscenario
def _create_or_update_param(key, value):
    Params = model('ir.config_parameter')
    ids = Params.search([('key', '=', key)])
    if ids:
        Params.write(ids, {'key': key, 'value': value})
    else:
        Params.create({'key': key, 'value': value})
コード例 #13
0
def _create_or_update_param(key, value):
    Params = model('ir.config_parameter')
    ids = Params.search([('key', '=', key)])
    if ids:
        Params.write(ids, {'key': key, 'value': value})
    else:
        Params.create({'key': key, 'value': value})
コード例 #14
0
def impl(ctx, fy_ref):
    """Create monthly periods `account.period` for the given fiscal year
    `account.fiscal.year`

    :param fy_ref: fiscal year code that needs periods
    :type fy_ref: string

    """
    assert '.' in fy_ref, "please use the full reference (e.g. scenario.%s)" % fy_ref
    module, xmlid = fy_ref.split('.', 1)
    _model, id = model('ir.model.data').get_object_reference(module, xmlid)
    assert _model == 'account.fiscalyear'
    fy = model('account.fiscalyear').get(id)
    fy.read('period_ids')
    if not fy.period_ids:
        model('account.fiscalyear').create_period([fy.id], {}, 1)
コード例 #15
0
def impl(ctx, name, digits, company_name):
    template = model('account.chart.template').get([("name", "=", name)])
    assert template
    root_account = template.account_root_id
    assert root_account
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    configuration_wizard = model('wizard.multi.charts.accounts').create({'code_digits': digits,
                                                                         'chart_template_id': template.id,
                                                                         'company_id': company.id,
                                                                         'currency_id': company.currency_id.id})

    vals = configuration_wizard.onchange_chart_template_id(template.id)
    configuration_wizard.write(vals['value'])
    # the onchange calls above may have changed this
    configuration_wizard.write({'code_digits': digits})
    configuration_wizard.execute()
コード例 #16
0
def impl(ctx):
    for row in ctx.table:
        date = datetime.date.today().strftime(row['date'])
        currency = model('res.currency').get([('name', '=', row['currency'])])
        ctype_id = False
        if row['type']:
            ctype = model('res.currency.rate.type').get([('name', '=', row['type'])])
            assert ctype
            ctype_id = ctype.id
        curr_rate = model('res.currency.rate').browse([('name', '=', date),
                                                       ('currency_id', '=', currency.id)])
        if not curr_rate:
            puts('creating new rate')
            values = {'name': date, 'currency_id': currency.id,
                      'rate': row['rate'], 'currency_rate_type_id': ctype_id}
            model('res.currency.rate').create(values)
        else:
            curr_rate[0].rate = row["rate"]
コード例 #17
0
def impl(ctx, logo_name, logo_path):
    cp_id = getattr(ctx, 'company_id')

    filename, extension = os.path.splitext(logo_path)
    assert extension.lower() in [
        '.png', '.gif', '.jpeg', '.jpg'
    ], "Image extension must be (.png, .gif or .jpeg)"

    encoded_image = get_encoded_image(ctx, logo_path)

    values = {
        'img': encoded_image,
        'name': logo_name,
        'type': extension[1:],
        'company_id': cp_id,
    }

    header_img = model('ir.header_img').browse([('name', '=', logo_name),
                                                ('company_id', '=', cp_id)])
    if header_img:
        header_img.write(values)
    else:
        model('ir.header_img').create(values)
コード例 #18
0
def impl(ctx, name, digits, company_name):
    template = model('account.chart.template').get([("name", "=", name)])
    assert template
    root_account = template.account_root_id
    assert root_account
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    configuration_wizard = model('wizard.multi.charts.accounts').create({
        'code_digits':
        digits,
        'chart_template_id':
        template.id,
        'company_id':
        company.id,
        'currency_id':
        company.currency_id.id
    })

    vals = configuration_wizard.onchange_chart_template_id(template.id)
    configuration_wizard.write(vals['value'])
    # the onchange calls above may have changed this
    configuration_wizard.write({'code_digits': digits})
    configuration_wizard.execute()
コード例 #19
0
def impl(ctx):
    for row in ctx.table:
        date = datetime.date.today().strftime(row['date'])
        currency = model('res.currency').get([('name', '=', row['currency'])])
        ctype_id = False
        if row['type']:
            ctype = model('res.currency.rate.type').get([('name', '=',
                                                          row['type'])])
            assert ctype
            ctype_id = ctype.id
        curr_rate = model('res.currency.rate').browse([('name', '=', date),
                                                       ('currency_id', '=',
                                                        currency.id)])
        if not curr_rate:
            puts('creating new rate')
            values = {
                'name': date,
                'currency_id': currency.id,
                'rate': row['rate'],
                'currency_rate_type_id': ctype_id
            }
            model('res.currency.rate').create(values)
        else:
            curr_rate[0].rate = row["rate"]
コード例 #20
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def import_csv_with_options(ctx, model_name, csvfile, options=None):
    """ import csv with options

    * handle special case to load "res.users" faster
    by setting `no_reset_password=True` in odoo context

    * currently supported options:
      * bulk={true|false}   load data in bulk mode (need a patch to odoo)
      * strict={true|false} verify that all rows are loaded
      * delimiter=","       choose CSV delimiter
    """

    tmp_path = ctx.feature.filename.split(os.path.sep)
    tmp_path = tmp_path[: tmp_path.index('features')] + ['data', csvfile]
    tmp_path = [str(x) for x in tmp_path]
    path = os.path.join(*tmp_path)
    assert os.path.exists(path)
    sep = options.get('delimiter', ',')
    strict = str2bool(options.get('strict', 'false'))

    data = csv.reader(open(path, 'rb'), delimiter=str(sep))
    head = data.next()
    values = list(data)

    context = ctx.oe_context
    ctx.loaded_objets = None

    if model_name == 'res.users':
        context = dict(context or {}, no_reset_password=True)

    if options.get('bulk') in ('True', 'true'):
        context = dict(context or {}, bulk_mode=True)

    result = model(model_name).load(head, values, context)
    ids = result['ids']
    if not ids:
        messages = '\n'.join('- %s' % msg for msg in result['messages'])
        raise Exception("Failed to load file '%s' "
                        "in '%s'. Details:\n%s" %
                        (csvfile, model_name, messages))

    elif strict and len(values) != len(ids):
        raise Exception("Loaded only %d of %d rows" % (len(ids),
                                                       len(values)))
    ctx.loaded_objets = (model_name, ids)
コード例 #21
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def import_csv_with_options(ctx, model_name, csvfile, options=None):
    """ import csv with options

    * handle special case to load "res.users" faster
    by setting `no_reset_password=True` in odoo context

    * currently supported options:
      * bulk={true|false}   load data in bulk mode (need a patch to odoo)
      * strict={true|false} verify that all rows are loaded
      * delimiter=","       choose CSV delimiter
    """

    tmp_path = ctx.feature.filename.split(os.path.sep)
    tmp_path = tmp_path[:tmp_path.index('features')] + ['data', csvfile]
    tmp_path = [str(x) for x in tmp_path]
    path = os.path.join(*tmp_path)
    assert os.path.exists(path)
    sep = options.get('delimiter', ',')
    strict = str2bool(options.get('strict', 'false'))

    data = csv.reader(open(path, 'rb'), delimiter=str(sep))
    head = data.next()
    values = list(data)

    context = ctx.oe_context
    ctx.loaded_objets = None

    if model_name == 'res.users':
        context = dict(context or {}, no_reset_password=True)

    if options.get('bulk') in ('True', 'true'):
        context = dict(context or {}, bulk_mode=True)

    result = model(model_name).load(head, values, context)
    ids = result['ids']
    if not ids:
        messages = '\n'.join('- %s' % msg for msg in result['messages'])
        raise Exception("Failed to load file '%s' "
                        "in '%s'. Details:\n%s" %
                        (csvfile, model_name, messages))

    elif strict and len(values) != len(ids):
        raise Exception("Loaded only %d of %d rows" % (len(ids), len(values)))
    ctx.loaded_objets = (model_name, ids)
コード例 #22
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    ctx.found_item = model('res.users').browse([('login', '=', 'admin')])
コード例 #23
0
def impl(ctx, webkit_path):
    key = model("ir.config_parameter").get([("key", "=", "webkit_path")])
    if key:
        key.write({"value": webkit_path})
    else:
        model("ir.config_parameter").create({"key": "webkit_path", "value": webkit_path})
コード例 #24
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def ref(xmlref):
    module, xmlid = xmlref.split('.', 1)
    model_, id_ = model('ir.model.data').get_object_reference(module, xmlid)
    return model(model_).browse(id_)
コード例 #25
0
def impl(ctx, company_name):
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    assert len(
        model('account.account').search([("company_id", "=", company.id)
                                         ])) == 0
コード例 #26
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    ctx.users = model('res.users').browse([('login', '!=', 'admin')])
コード例 #27
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    ctx.found_item = model('res.users').browse([('login', '=', 'admin')])
コード例 #28
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    groups = model('res.groups').browse([])
    for user in ctx.found_items:
        assign_groups(user, groups)
コード例 #29
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    logins = [row['login'] for row in ctx.table]
    ctx.found_items = model('res.users').browse([('login', 'in', logins)])
    assert_equal(len(ctx.found_items), len(logins))
コード例 #30
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    logins = [row['login'] for row in ctx.table]
    ctx.found_items = model('res.users').browse([('login', 'in', logins)])
    assert_equal(len(ctx.found_items), len(logins))
コード例 #31
0
def impl(context, company_name):
    company = model('res.company').get([('name', '=', company_name)])
    assert company
    assert len(model('account.account').search([("company_id", "=", company.id)])) > 0
コード例 #32
0
def impl(ctx):
    for jrn in model('account.journal').browse([]):
        jrn.write({'update_posted': True})
コード例 #33
0
def impl(ctx):
    assert model('ir.module.module').get(['name = account', 'state = installed'])
コード例 #34
0
def impl(ctx):
    assert model('ir.module.module').get(
        ['name = account', 'state = installed'])
コード例 #35
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    groups = model('res.groups').browse([])
    for user in ctx.found_items:
        assign_groups(user, groups)
コード例 #36
0
def impl(ctx):
    for jrn in model('account.journal').browse([]):
        jrn.write({'update_posted': True})
コード例 #37
0
ファイル: user_config.py プロジェクト: esciara/oerpscenario
def impl(ctx):
    ctx.users = model('res.users').browse([('login', '!=', 'admin')])
コード例 #38
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def ref(xmlref):
    module, xmlid = xmlref.split('.', 1)
    model_, id_ = model('ir.model.data').get_object_reference(module, xmlid)
    return model(model_).browse(id_)