diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c90a29b --- /dev/null +++ b/README.rst @@ -0,0 +1 @@ +Trim email field in partner form. diff --git a/__openerp__.py b/__openerp__.py index cba733b..fa99c68 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- { 'name': "Trim email's field", - 'summary': """""", - 'description': """""", + 'summary': "", 'author': "Ivan Yelizariev", 'website': "https://yelizariev.github.io", diff --git a/models.py b/models.py index a71d751..a7ab8c4 100644 --- a/models.py +++ b/models.py @@ -8,14 +8,16 @@ class res_partner_strip_email(models.Model): @api.one def write(self, vals): - if 'email' in vals and type(vals['email']) is not bool: - vals['email'] = vals['email'].strip() - res = super(res_partner_strip_email, self).write(vals) - return res + vals = self._check_email_field(vals) + return super(res_partner_strip_email, self).write(vals) @api.model def create(self, vals): - if vals['email']: + vals = self._check_email_field(vals) + return super(res_partner_strip_email, self).create(vals) + + def _check_email_field(self, vals): + if not isinstance(vals['email'], bool) and 'email' in vals or \ + isinstance(vals['email'], bool) and vals['email']: vals['email'] = vals['email'].strip() - res = super(res_partner_strip_email, self).create(vals) - return res + return vals