12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from openerp import _
- from openerp.exceptions import ValidationError
- def pre_init_hook(cr):
- """Make sure there are no duplicates before installing the module.
- If you define a unique key in Odoo that cannot be applied, Odoo will log a
- warning and install the module without that constraint. Since this module
- is useless without those constraints, we check here if all will work before
- installing, and provide a user-friendly message in case of failure.
- """
- errors = list()
-
- cr.execute("""SELECT c.email, l.name, COUNT(c.id)
- FROM
- mail_mass_mailing_contact AS c
- INNER JOIN mail_mass_mailing_list AS l ON c.list_id = l.id
- GROUP BY l.name, l.id, c.email
- HAVING COUNT(c.id) > 1""")
- for result in cr.fetchall():
- errors.append(
- _("{0} appears {2} times in list {1}.").format(*result))
-
- cr.execute("""SELECT name, COUNT(id)
- FROM mail_mass_mailing_list
- GROUP BY name
- HAVING COUNT(id) > 1""")
- for result in cr.fetchall():
- errors.append(
- _("There are {1} lists with name {0}.").format(*result))
-
- if errors:
- raise ValidationError(
- _("Fix this before installing:") +
- "".join("\n" + e for e in errors))
|