Created
March 3, 2015 10:10
-
-
Save lepistone/3ca65107fc7344440777 to your computer and use it in GitHub Desktop.
How to create and pre-populate a not null column in odoo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _auto_init(self, cr, context): | |
"""Fill in the required consignee column with default values. | |
This is similar to the solution used in mail_alias.py in the core. | |
The installation of the module will succeed with no errors, and the | |
column will be required immediately (the previous solution made it | |
required only on the first module update after installation). | |
""" | |
# create the column non required | |
self._columns['consignee_id'].required = False | |
super(SaleOrder, self)._auto_init(cr, context=context) | |
# fill in the empty records | |
no_consignee_ids = self.search(cr, SUPERUSER_ID, [ | |
('consignee_id', '=', False) | |
], context=context) | |
self.write(cr, SUPERUSER_ID, no_consignee_ids, | |
{'consignee_id': SUPERUSER_ID}, context) | |
# make the column required again | |
self._columns['consignee_id'].required = True | |
super(SaleOrder, self)._auto_init(cr, context=context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment