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 check_accounts(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, state): wiz = model('credit.control.marker').create({'name': state}) lines = model('credit.control.line').search([('state', '=', 'draft')]) assert lines ctx.lines = lines wiz.write({'line_ids': lines}) wiz.mark_lines()
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, line_number, level, policy_name): assert_true(ctx.invoice) policy = model('credit.control.policy').get([('name', '=', policy_name)]) assert_true(policy) lines = model('credit.control.line').search([('invoice_id', '=', ctx.invoice.id), ('level', '=', level), ('policy_id', '=', policy.id)]) assert_equal(len(lines), line_number)
def impl(ctx, fy_ref): 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 impl(ctx, partner, number, level, move_line_name, amount): to_check = model('credit.control.line').search([('partner_id.name', '=', partner), ('level', '=', level), ('amount_due', '=', amount), ('move_line_id.name', '=', move_line_name), ('state', 'in', ('draft', 'ignored'))]) assert_equal(len(to_check), int(number), msg="More than %s found" % number) lines = model('credit.control.line').browse(to_check) assert set(['ignored', 'draft']) == set(lines.state)
def impl(ctx, line_number, level, policy_name): assert_true(ctx.invoice) policy = model('credit.control.policy').get([('name', '=', policy_name)]) assert_true(policy) lines = model('credit.control.line').search([ ('invoice_id', '=', ctx.invoice.id), ('level', '=', level), ('policy_id', '=', policy.id) ]) assert_equal(len(lines), line_number)
def impl(ctx, partner, number, level, move_line_name, amount): to_check = model('credit.control.line').search([('partner_id.name', '=', partner), ('level', '=', level), ('amount_due', '=', amount), ('move_line_id.name', '=', move_line_name), ('state', 'in', ('draft', 'ignored'))]) assert_equal(len(to_check), int(number), msg="More than %s found" % number) lines = model('credit.control.line').browse(to_check) assert ['ignored', 'draft'] == lines.state
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, policy_oid): policy = model('credit.control.policy').get(policy_oid) assert policy, 'No policy % found' % policy_oid acc_obj = model('account.account') accounts = [] for row in ctx.table: acc = acc_obj.get(['code = %s' % row['account code']]) assert acc, "Account with code %s not found" % row['account code'] accounts.append(acc) policy.write({'account_ids': [x.id for x in accounts]})
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, partner, level, move_line_name, amount): print ctx, partner, level, move_line_name, amount to_ignore = model('credit.control.line').search([ ('partner_id.name', '=', partner), ('level', '=', level), ('amount_due', '=', amount), ('move_line_id.name', '=', move_line_name) ]) assert to_ignore wiz = model('credit.control.marker').create({'name': 'ignored'}) ctx.lines = to_ignore wiz.write({'line_ids': to_ignore}) wiz.mark_lines() assert model('credit.control.line').get(to_ignore[0]).state == 'ignored'
def impl(ctx, partner, level, move_line_name, amount): print ctx, partner, level, move_line_name, amount to_ignore = model('credit.control.line').search([('partner_id.name', '=', partner), ('level', '=', level), ('amount_due', '=', amount), ('move_line_id.name', '=', move_line_name)]) assert to_ignore wiz = model('credit.control.marker').create({'name': 'ignored'}) ctx.lines = to_ignore wiz.write({'line_ids': to_ignore}) wiz.mark_lines() assert model('credit.control.line').get(to_ignore[0]).state == 'ignored'
def impl(ctx, invoice_name, level_name, policy_name): invoice = model('account.invoice').get([('number', '=', invoice_name)]) assert_true(invoice, msg='No invoices found') level = model('credit.control.policy.level').get([('name', '=', level_name)]) assert_true(level, 'level not found') policy = model('credit.control.policy').get([('name', '=', policy_name)]) assert_true(policy, 'Policy not found') assert_equal(policy.id, level.policy_id.id) context = {'active_ids': [invoice.id]} data = {'new_policy_id': policy.id, 'new_policy_level_id': level.id} wizard = model('credit.control.policy.changer').create(data, context=context) ctx.wizard = wizard
def impl(ctx, invoice_name, level_name, policy_name): invoice = model('account.invoice').get([('number', '=', invoice_name)]) assert_true(invoice, msg='No invoices found') level = model('credit.control.policy.level').get([('name', '=', level_name) ]) assert_true(level, 'level not found') policy = model('credit.control.policy').get([('name', '=', policy_name)]) assert_true(policy, 'Policy not found') assert_equal(policy.id, level.policy_id.id) context = {'active_ids': [invoice.id]} data = {'new_policy_id': policy.id, 'new_policy_level_id': level.id} wizard = model('credit.control.policy.changer').create(data, context=context) ctx.wizard = wizard
def impl(ctx): def _row_to_dict(row): return dict((name, row[name]) for name in row.headings if row[name]) rows = map(_row_to_dict, ctx.table) def _parse_date(value): return time.strftime(value) if '%' in value else value for row in rows: account = model('account.account').get(['name = %s' % row['account']]) assert account, "no account named %s found" % row['account'] policy = model('credit.control.policy').get( ['name = %s' % row['policy']]) assert policy, "No policy %s found" % row['policy'] partner = model('res.partner').get(['name = %s' % row['partner']]) assert partner, "No partner %s found" % row['partner'] maturity_date = _parse_date(row['date due']) move_line = model('account.move.line').get([ 'name = %s' % row['move line'], 'date_maturity = %s' % maturity_date ]) assert move_line, "No move line %s found" % row['move line'] level = model('credit.control.policy.level').get( ['name = %s' % row['policy level'], 'policy_id = %s' % policy.id]) assert level, "No level % found" % row['policy level'] domain = [ ['account_id', '=', account.id], ['policy_id', '=', policy.id], ['partner_id', '=', partner.id], ['policy_level_id', '=', level.id], ['amount_due', '=', row.get('amount due', 0.0)], ['state', '=', row['state']], ['level', '=', row.get('level', 0.0)], ['channel', '=', row['channel']], ['balance_due', '=', row.get('balance', 0.0)], ['date_due', '=', _parse_date(row['date due'])], ['date', '=', _parse_date(row['date'])], ['move_line_id', '=', move_line.id], ] if row.get('currency'): curreny = model('res.currency').get( ['name = %s' % row['currency']]) assert curreny, "No currency %s found" % row['currency'] domain.append(('currency_id', '=', curreny.id)) lines = model('credit.control.line').search(domain) assert lines, "no line found for %s" % repr(row) assert len(lines) == 1, "Too many lines found for %s" % repr(row) date_lines = model('credit.control.line').search([('date', '=', ctx.found_item.date)]) assert len(date_lines) == len(ctx.table.rows), "Too many lines generated"
def impl(ctx, inv_name): Invoice = model('account.invoice') invoice = Invoice.get([('name', '=', inv_name)]) assert invoice ctx.execute_steps(""" When I pay %f on the invoice "%s" """ % (invoice.residual, inv_name))
def impl(ctx, level_name, invoice_name): invoice = model('account.invoice').get([('number', '=', invoice_name)]) assert_true(invoice, msg='No invoices found') level = model('credit.control.policy.level').get([('name', '=', level_name)]) assert_true(level, 'level not found') assert_true(ctx.wizard) move_ids = [x.id for x in ctx.wizard.move_line_ids] created_id = model('credit.control.line').search([('move_line_id', 'in', move_ids), ('manually_overridden', '=', False)]) assert len(created_id) == 1 created = model('credit.control.line').get(created_id[0]) ctx.created = created assert_equal(created.policy_level_id.id, level.id) assert_equal(created.invoice_id.id, invoice.id) assert_equal(created.invoice_id.credit_policy_id.id, level.policy_id.id)
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, invoice_name): invoice = model('account.invoice').get([('number', '=', invoice_name)]) assert_true(invoice, msg='No invoices found') man_lines = (x for x in invoice.credit_control_line_ids if x.manually_overridden) assert_true(next(man_lines, None), 'No manual change on the invoice') ctx.invoice = invoice
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, level_name, invoice_name): invoice = model('account.invoice').get([('number', '=', invoice_name)]) assert_true(invoice, msg='No invoices found') level = model('credit.control.policy.level').get([('name', '=', level_name) ]) assert_true(level, 'level not found') assert_true(ctx.wizard) move_ids = [x.id for x in ctx.wizard.move_line_ids] created_id = model('credit.control.line').search([ ('move_line_id', 'in', move_ids), ('manually_overridden', '=', False) ]) assert len(created_id) == 1 created = model('credit.control.line').get(created_id[0]) ctx.created = created assert_equal(created.policy_level_id.id, level.id) assert_equal(created.invoice_id.id, invoice.id) assert_equal(created.invoice_id.credit_policy_id.id, level.policy_id.id)
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 attach_file(ctx, filepath, res_model, oid): rec = model(res_model).get(oid) assert rec, "xmlid not found for this object" tmp_path = ctx.feature.filename.split(os.path.sep) tmp_path = tmp_path[:tmp_path.index('features')] + ['data', filepath] tmp_path = [str(x) for x in tmp_path] path = os.path.join(*tmp_path) with open(path, "rb") as f: file_data = base64.b64encode(f.read()) values = { 'name': os.path.basename(filepath), 'res_id': rec.id, 'res_model': res_model, 'datas': file_data, } model('ir.attachment').create(values)
def impl(ctx, users): # search groups by name and full name group_names = [row['group_name'] for row in ctx.table] group_names = list(set(group_names)) group_full_names = [name for name in group_names if '/' in name] group_single_names = [name for name in group_names if not '/' in name] ModulCategory = model('ir.module.category') groups = [] group_full_names_category = [] 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 = ModulCategory.search([('name', '=', categ)]) assert category_ids, 'no category named %s' % categ condition = [ '&', ('name', '=', name), ('category_id', 'in', category_ids) ] # Take the category_id to build the domain # [ # ('&',('name','=','User'), ('category_id','=',40)), # ('&',('name','=','User'), ('category_id','=',47)), # ] 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)) #assert_equal(len(groups), len(group_names)) assert users in ('user', 'users') if users == "users": for user in ctx.found_items: assign_groups(user, groups) if users == "user": assign_groups(ctx.found_item, groups)
def impl(ctx): def _row_to_dict(row): return dict((name, row[name]) for name in row.headings if row[name]) rows = map(_row_to_dict, ctx.table) def _parse_date(value): return time.strftime(value) if '%' in value else value for row in rows: account = model('account.account').get(['name = %s' % row['account']]) assert account, "no account named %s found" % row['account'] policy = model('credit.control.policy').get(['name = %s' % row['policy']]) assert policy, "No policy %s found" % row['policy'] partner = model('res.partner').get(['name = %s' % row['partner']]) assert partner, "No partner %s found" % row['partner'] maturity_date = _parse_date(row['date due']) move_line = model('account.move.line').get(['name = %s' % row['move line'], 'date_maturity = %s' % maturity_date]) assert move_line, "No move line %s found" % row['move line'] level = model('credit.control.policy.level').get(['name = %s' % row['policy level'], 'policy_id = %s' % policy.id]) assert level, "No level % found" % row['policy level'] domain = [['account_id', '=', account.id], ['policy_id', '=', policy.id], ['partner_id', '=', partner.id], ['policy_level_id', '=', level.id], ['amount_due', '=', row.get('amount due', 0.0)], ['state', '=', row['state']], ['level', '=', row.get('level', 0.0)], ['channel', '=', row['channel']], ['balance_due', '=', row.get('balance', 0.0)], ['date_due', '=', _parse_date(row['date due'])], ['date', '=', _parse_date(row['date'])], ['move_line_id', '=', move_line.id], ] if row.get('currency'): curreny = model('res.currency').get(['name = %s' % row['currency']]) assert curreny, "No currency %s found" % row['currency'] domain.append(('currency_id', '=', curreny.id)) lines = model('credit.control.line').search(domain) assert lines, "no line found for %s" % repr(row) assert len(lines) == 1, "Too many lines found for %s" % repr(row) date_lines = model('credit.control.line').search([('date', '=', ctx.found_item.date)]) assert len(date_lines) == len(ctx.table.rows), "Too many lines generated"
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 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) if values: context = ctx.oe_context ctx.loaded_objets = None if model_name == 'res.users': context = dict(context or {}, no_reset_password=True) if str2bool(options.get('bulk')): 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))) else: # valid file with header and no further lines: noop ids = [] 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) if values: context = ctx.oe_context ctx.loaded_objets = None if model_name == 'res.users': context = dict(context or {}, no_reset_password=True) if str2bool(options.get('bulk')): 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))) else: # valid file with header and no further lines: noop ids = [] ctx.loaded_objets = (model_name, ids)
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): assert ctx.found_item # Must be a cleaner way to do it assert model("credit.control.run").get(ctx.found_item.id).state == 'done'
def impl(ctx): model('credit.control.line').browse([]).unlink()
def impl(ctx, state): assert ctx.lines lines = model('credit.control.line').search([('state', '!=', state), ('id', 'in', ctx.lines)]) assert not lines
def impl(ctx): for jrn in model('account.journal').browse([]): jrn.write({'update_posted': True})
def impl(ctx, state): assert model('credit.control.line').search(['state = %s' % state])
def impl(ctx): groups = model('res.groups').browse([]) for user in ctx.found_items: assign_groups(user, groups)
def check_no_account(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 check_accounts(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 allow_cancelling(ctx): for jrn in model('account.journal').browse([]): jrn.write({'update_posted': True})
def assert_account_installed(ctx): assert model('ir.module.module').get([ 'name = account', 'state = installed' ])
def impl(ctx): ctx.users = model('res.users').browse([('login', '!=', 'admin')])
def impl(ctx): ctx.found_item = model('res.users').browse([('login', '=', 'admin')])
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))