From c792e1bcbb10991c43ff5cb802dd6e8e4aaa39f2 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Tue, 29 Jul 2014 21:07:13 +0200 Subject: [PATCH] [IMP] _set_default_value_on_column avoiding useless queries --- partner_firstname/partner.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/partner_firstname/partner.py b/partner_firstname/partner.py index 85dd9b53c..4be5cca8d 100644 --- a/partner_firstname/partner.py +++ b/partner_firstname/partner.py @@ -34,18 +34,12 @@ class ResPartner(orm.Model): 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 cr.fetchone(): - cr.execute('UPDATE res_partner set lastname = name WHERE name ' - 'IS NOT NULL') - # 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") + cr.execute('UPDATE res_partner SET lastname = name WHERE name ' + 'IS NOT NULL AND lastname IS NULL') + cr.execute('ALTER TABLE res_partner ALTER COLUMN lastname ' + 'SET NOT NULL') + _logger.info("NOT NULL constraint for " + "res_partner.lastname correctly set") return res def _prepare_name_custom(self, cursor, uid, partner, context=None):