Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

ProgrammingError can't adapt type 'account.journal'

By
Melvin Martinez
on 10/1/14, 10:56 AM 2,569 views

A onchange method that try to modify the inherited domain and presents me the following error, this is the code I'm using and the new api..

File "/usr/lib/python2.7/dist-packages/psycopg2/extensions.py", line 129, in getquoted 

pobjs = [adapt(o) for o in self._seq]

ProgrammingError: can't adapt type 'account.journal'

@api.multi
def onchange_company_id(self, company_id, part_id, type, invoice_line, currency_id):
        result = super(account_invoice, self).onchange_company_id(company_id, part_id, type, invoice_line, currency_id)

        obj_jrnl = self.env['account.journal']
        jrnl_ids = result['domain']['journal_id']
        jrd = []

        for jrnl_id in jrnl_ids:
            for lst in jrnl_id[2]:
                jrnl = obj_jrnl.search([('id','=',lst)])
                for rec_jrnl in obj_jrnl.browse(jrnl):
                    if type in ('out_invoice', 'in_invoice'):
                        if rec_jrnl.type_doc.main_doc:                  # <-- Line Error
                            jrd.append(lst)
                    else:
                        if not rec_jrnl.cat_doc.void:             
                            jrd.append(lst)
            if jrd:
                result['value'] = {'journal_id': jrd[0]}
                result['domain'] = {'journal_id':  [('id', 'in', jrd)]}
                
        return result

The field is many2one type_doc to another table and main_doc is a boolean field, this method works flawlessly in 6.1 and 7.0

1

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 10/2/14, 8:19 AM

One line above your error you mention "type" but you do not specify what it is. 

Normally this error shows up when you want to for example browse over a record but the id is a boolean (false) instead of an integer.

Also make sure that type_doc is always provided (mandatory) because in your code you automatically assume that it is!

thanks ludo the problem was Logic, rewrote the code and ready

Melvin Martinez
on 10/2/14, 10:09 AM
0
Melvin Martinez
On 10/2/14, 10:10 AM

The problem was logic, the correct code is this:

        for jrnl_id in jrnl_ids[0][2]:
            rec_jrnl = obj_jrnl.browse(jrnl_id)
            if type in ('out_invoice', 'in_invoice'):
                if rec_jrnl.type_doc.main_doc:
                    jrd.append(jrnl_id)
                else:
                    if not rec_jrnl.cat_doc.void:
                       jrd.append(jrnl_id)
            if jrd:
                result['value'] = {'journal_id': jrd[0]}
                result['domain'] = {'journal_id':  [('id', 'in', jrd)]}
                
        return result

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/1/14, 10:56 AM
Seen: 2569 times
Last updated: 3/16/15, 8:10 AM