How to change the field name of a model in Odoo

I wrote a task model that had the field "date" (which represented the deadline of the task), however, I decided that it would be best to have a initial and a deadline date, how do I update my model so that the data in date would migrate to deadline date?

Here is what I had:

_columns = {
    'title': fields.char('Title', size=128, required=True),
    'date': fields.date('Date', required=True),
    'note': fields.text('Notes')
        }

And this is what I'd like to have:

_columns = {
    'title': fields.char('Title', size=128, required=True),
    'dateInitial': fields.date('Initial Date', required=True),
    'dateDeadline': fields.date('Deadline Date', required=True),
    'note': fields.text('Notes')
}

Answers


Try following steps:

  • Add two new fields 'dateInitial' and dateDeadline along with the field 'date'.

  • Now update your module so that those two fields get included into the database table.

  • Now go to database environment, and try to execute following query. I assume your table name is 'task'

    update task set dateDeadline=date;

  • This will bring up all the data of 'date' field to 'dateDeadline'

  • Now, try to execute the following query to remove the values from 'date' field:

    update task set date=null;

  • Now try to execute the following query to drop the column 'date' from database:

    alter table task drop column date;

  • Now, remove the field from your '.py' file and update the module again.

Hope this helps !!.


As per my opinion is that no need to add the two separate date for each inline date and Deadline date.

You can do just the below way just add the new string from the existing model field Date to Deadline Date and add a new field for initial date.

_columns = {
    'title': fields.char('Title', size=128, required=True),
    'date': fields.date(string='Deadline Date', required=True),
    'inline_date:fields.date(string='Initial Date'),
    'note': fields.text('Notes')
        }

In Odoo new API 8.0 how the each field treated : when ever we are define the new field into the new model or some existing model then Its work as field name as the your view (Odoo Views) field string when there is no default field string define into our existing field in our model.

and If we are adding the new string using string attribute of our exciting field then It will be override that field name and your string attribute of field will directly apply into our views.

I hope my answer may helpful for you :)


Here the another way with following steps

1)Go technical setting --> views and delete the respective views,

2)Rename your field in py and xml

3)upgrade your module it will work


Need Your Help

Insight on handling static library revisions (i.e. binaries) with git

git version-control static-libraries git-submodules

I'm looking for some insight on how to handle git repositories that each utilize a (large) static library, and have some concerns about a solution I thought about.

Android 5.0+ doesn't change checkbox image

android android-layout android-support-library android-appcompat

I'm trying to make a custom multi image pick gallery. When I click on the CheckBox logs show me, that everything has to work: OnCheckedChanged and OnClick callbacks are fired, but there's no animat...