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


The question has been closed

AJ Schrafel Paper Corp
on 06/24/2013 00: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/", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server/openerp/osv/", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server/openerp/osv/", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/server/openerp/osv/", line 4434, in create
    cr.execute('insert into "'+self._table+'" (id'+upd0+") values ("+str(id_new$
  File "/opt/openerp/server/openerp/", line 161, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/openerp/server/openerp/", 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.

2 Answers
Timothy Solomon
Best Answer

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.


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..!

Timothy Solomon

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.

Best Answer

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

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')