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.

4

How do I access columns created by openerp in a XML view? [Closed]

By
AJ Schrafel Paper Corp
on 4/20/13, 5:26 PM 5,333 views

The Question has been closed

by
AJ Schrafel Paper Corp
on 06/24/2013 01:51:22

When I try to put a column in my custom module called create_date, i get the following error.

    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/server/openerp/osv/orm.py", line 4434, in create
    cr.execute('insert into "'+self._table+'" (id'+upd0+") values ("+str(id_new$
  File "/opt/openerp/server/openerp/sql_db.py", line 161, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/openerp/server/openerp/sql_db.py", line 226, in execute
    res = self._obj.execute(query, params)
ProgrammingError: column "create_date" specified more than once
LINE 1: ...d,"attachment_id","create_date","name",create_uid,create_dat...

I am assuming this is because openerp automatically creates a column called create_date, which is fine. But how do i access that information in my XML file?

I get the following error when I try to access create_date in the XML without decalring it in the python file.

Can't find field 'create_date' in the following view parts composing the view of object model 'custom module': * custom.module.tree
Either you wrongly customized this view, or some modules bringing those views are not compatible with your current data model

So I cannot define the column create_date, and i cannot access it in the XML views unless it is defined. What should i do to display the column created by openerp to the user?

Creating my own field to store the creation data seems duplicative and silly.

3
Timothy Solomon
On 4/22/13, 7:32 AM

There is an easier way, just add the columns in your model:

_columns = {
        ...
        'create_date' : fields.datetime('Date Created', readonly=True),
        'create_uid' : fields.many2one('res.users', 'by User', readonly=True),
    }

Then you can use as a normal column in xml

NOTE - readonly=True is required for this to work.

AJ Schrafel Paper Corp
on 4/24/13, 5:35 PM

Hi Timothy, i want bit more clarity. I am using Restful API for Openerp V7. I want write my own date into create_date field instead of letting ORM to put current system date, as well as read create_date. If i set readonly=True, then how could i write. Please give me some suggestion. Thank you..!

santoshnayak
on 10/17/13, 6:48 AM

I dont think you can overwrite the create_date. Why not just use a new date field for your date? create_date is an existing field on all tables so you cant use that name for your field.

Timothy Solomon
on 7/3/14, 6:41 AM
2
klacus
On 4/21/13, 3:06 AM

Yes, because you need a different way to read this data.

I think the good solution is this:

perm_read(cr, user, ids, context=None, details=True)

Returns some metadata about the given records.
Parameters: details – if True, *_uid fields are replaced with the name of the user
Returns:    list of ownership dictionaries for each requested record
Return type:    list of dictionaries with the following keys:

    id: object id
    create_uid: user who created the record
    create_date: date when the record was created
    write_uid: last user who changed the record
    write_date: date of the last change to the record
    xmlid: XML ID to use to refer to this record (if there is one), in format module.name

You need to create a field and link in xml what is displaying the result of perm read of the current record. Just use google in orm methods... in documentation, older forums, like this

perms = self.perm_read(cr,uid,ids)
wr_date =  perms[0].get('write_date', 'n/a')

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 4/20/13, 5:26 PM
Seen: 5333 times
Last updated: 3/16/15, 8:10 AM