You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
[9.0][MIG][mass_mailing_custom_unsubscribe] Migrate. - Imported last updates from v8. - Adapted to v9. - Added a saner default to `mass_mailing.salt` configuration parameter by reusing `database.secret` if available, hoping that some day https://github.com/odoo/odoo/pull/12040 gets merged. - Updated README. - Increase security, drop backwards compatibility. Security got improved upstream, which would again break compatibility among current addon and future master upstream. I choose to break it now and keep it secured future-wise, so I drop the backwards compatibility features. - Includes tour tests. - Removes outdated tests. - Extends the mailing list management form when unsubscriber is a contact. - Adds a reason form even if he is not. - Avoids all methods that were not model-agnostic. [FIX][mass_mailing_custom_unsubscribe] Reasons noupdate After this fix, when you update the addon, you will not lose your customized reasons. [FIX] Compatibilize with mass_mailing_partner Current test code was based on the assumption that the `@api.model` decorator on `create()` ensured an empty recordset when running the method, but that's not true. This was causing an incompatibility betwee these tests and the `mass_mailing_partner` addon, which works assuming 0-1 recordsets. Now records are created from an empty recordset, and thus tests work everywhere. Update instructions If the user does not add the unsubscribe snippet, nothing will happen, so it's added to README to avoid confusion when testing/using the addon. [FIX] Use the right operator to preserve recordsets order Using `|=` sorts records at will each time (treating them as Python's `set`). Using `+=` always appends a record to the end of the set. Since we are using the record position in the set, this caused the test to work sometimes and fail other times. Now it works always.
8 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import _, api, fields, models
  5. from .. import exceptions
  6. class MailUnsubscription(models.Model):
  7. _name = "mail.unsubscription"
  8. _inherit = "mail.thread"
  9. _rec_name = "date"
  10. date = fields.Datetime(
  11. default=lambda self: self._default_date(),
  12. required=True)
  13. email = fields.Char(
  14. required=True)
  15. mass_mailing_id = fields.Many2one(
  16. "mail.mass_mailing",
  17. "Mass mailing",
  18. required=True,
  19. help="Mass mailing from which he was unsubscribed.")
  20. unsubscriber_id = fields.Reference(
  21. lambda self: self._selection_unsubscriber_id(),
  22. "Unsubscriber",
  23. required=True,
  24. help="Who was unsubscribed.")
  25. reason_id = fields.Many2one(
  26. "mail.unsubscription.reason",
  27. "Reason",
  28. ondelete="restrict",
  29. required=True,
  30. help="Why the unsubscription was made.")
  31. details = fields.Char(
  32. help="More details on why the unsubscription was made.")
  33. details_required = fields.Boolean(
  34. related="reason_id.details_required")
  35. @api.model
  36. def _default_date(self):
  37. return fields.Datetime.now()
  38. @api.model
  39. def _selection_unsubscriber_id(self):
  40. """Models that can be linked to a ``mail.mass_mailing``."""
  41. return self.env["mail.mass_mailing"]._get_mailing_model()
  42. @api.multi
  43. @api.constrains("details", "reason_id")
  44. def _check_details_needed(self):
  45. """Ensure details are given if required."""
  46. for one in self:
  47. if not one.details and one.details_required:
  48. raise exceptions.DetailsRequiredError(
  49. _("Please provide details on why you are unsubscribing."))
  50. class MailUnsubscriptionReason(models.Model):
  51. _name = "mail.unsubscription.reason"
  52. _order = "sequence, name"
  53. name = fields.Char(
  54. index=True,
  55. translate=True,
  56. required=True)
  57. details_required = fields.Boolean(
  58. help="Check to ask for more details when this reason is selected.")
  59. sequence = fields.Integer(
  60. index=True,
  61. help="Position of the reason in the list.")