Browse Source

[FIX] IntegrityError: column "lastname" contains null values

pull/14/head
Lorenzo Battistini 10 years ago
parent
commit
ae4c47d9ed
  1. 24
      partner_firstname/partner.py

24
partner_firstname/partner.py

@ -29,19 +29,23 @@ class ResPartner(orm.Model):
_inherit = 'res.partner'
def init(self, cursor):
cursor.execute('SELECT id FROM res_partner WHERE lastname IS NOT NULL '
def _set_default_value_on_column(self, cr, column_name, context=None):
res = super(ResPartner, self)._set_default_value_on_column(
cr, column_name, context=context)
if column_name == 'lastname':
cr.execute('SELECT id FROM res_partner WHERE lastname IS NOT NULL '
'Limit 1')
if not cursor.fetchone():
cursor.execute('UPDATE res_partner set lastname = name WHERE name '
if not cr.fetchone():
cr.execute('UPDATE res_partner set lastname = name WHERE name '
'IS NOT NULL')
# Create Sql constraint if table is not empty
cursor.execute('SELECT id FROM res_partner Limit 1')
if cursor.fetchone():
cursor.execute('ALTER TABLE res_partner ALTER COLUMN lastname '
# Create Sql constraint if table is not empty
cr.execute('SELECT id FROM res_partner Limit 1')
if cr.fetchone():
cr.execute('ALTER TABLE res_partner ALTER COLUMN lastname '
'SET NOT NULL')
_logger.info("NOT NULL constraint for res_partner.lastname "
"correctly set")
_logger.info("NOT NULL constraint for "
"res_partner.lastname correctly set")
return res
def _prepare_name_custom(self, cursor, uid, partner, context=None):
"""

Loading…
Cancel
Save