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
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]})
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})
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 })
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})
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'
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)
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)
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})
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()
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"]
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)
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()
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"]
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)
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)
def impl(ctx): ctx.found_item = model('res.users').browse([('login', '=', 'admin')])
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})
def ref(xmlref): module, xmlid = xmlref.split('.', 1) model_, id_ = model('ir.model.data').get_object_reference(module, xmlid) return model(model_).browse(id_)
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
def impl(ctx): ctx.users = model('res.users').browse([('login', '!=', 'admin')])
def impl(ctx): groups = model('res.groups').browse([]) for user in ctx.found_items: assign_groups(user, groups)
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))
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
def impl(ctx): for jrn in model('account.journal').browse([]): jrn.write({'update_posted': True})
def impl(ctx): assert model('ir.module.module').get(['name = account', 'state = installed'])
def impl(ctx): assert model('ir.module.module').get( ['name = account', 'state = installed'])