Ejemplo n.º 1
0
    def test_str(self):
        records = erppeek.RecordList(self.model('foo.bar'), [(13, 'treize'),
                                                             (17, 'dix-sept')])
        rec1 = self.model('foo.bar').browse(42)
        rec2 = records[0]
        rec3 = self.model('foo.bar').browse(404)

        self.assertEqual(str(rec1), 'name_42')
        self.assertEqual(str(rec2), 'treize')
        self.assertEqual(rec1._name, 'name_42')
        self.assertEqual(rec2._name, 'treize')

        # Broken name_get
        self.assertEqual(str(rec3), 'foo.bar,404')

        self.assertCalls(
            OBJ('foo.bar', 'fields_get_keys'),
            OBJ('foo.bar', 'name_get', [42]),
            OBJ('foo.bar', 'name_get', [404]),
        )

        # This str() is never updated (for performance reason).
        rec1.refresh()
        rec2.refresh()
        rec3.refresh()
        self.assertEqual(str(rec1), 'name_42')
        self.assertEqual(str(rec2), 'treize')
        self.assertEqual(str(rec3), 'foo.bar,404')

        self.assertCalls()
        self.assertOutput('')
Ejemplo n.º 2
0
def impl(ctx, word1, word2, word3, model_name, domain):
    # n is counted as word there for the english grammar, but not used
    # words can be 'possibly' of 'possibly inactive'
    active_text = ' '.join(w for w in (word1, word2, word3) if w and w != 'n')
    assert active_text in ('', 'inactive', 'active', 'possibly inactive')
    Model = model(model_name)
    ctx.search_model_name = model_name
    oe_context = getattr(ctx, 'oe_context', None)
    values = parse_domain(domain)
    active = True
    if active_text == 'inactive':
        active = False
    elif active_text == 'possibly inactive':
        active = None
    domain = build_search_domain(ctx, model_name, values, active=active)

    if domain is None:
        ctx.found_item = None
        ctx.found_items = erppeek.RecordList(Model, [])
    else:
        ctx.found_items = Model.browse(domain, context=oe_context)
        if len(ctx.found_items) == 1:
            ctx.found_item = ctx.found_items[0]
        else:
            ctx.found_item = None