test_mail_models_mail.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. class MailTestPortal(models.Model):
  5. """ A model intheriting from mail.thread with some fields used for portal
  6. sharing, like a partner, ..."""
  7. _description = 'Chatter Model for Portal'
  8. _name = 'mail.test.portal'
  9. _inherit = [
  10. 'mail.thread',
  11. 'portal.mixin',
  12. ]
  13. name = fields.Char()
  14. partner_id = fields.Many2one('res.partner', 'Customer')
  15. def _compute_access_url(self):
  16. self.access_url = False
  17. for record in self.filtered('id'):
  18. record.access_url = '/my/test_portal/%s' % self.id
  19. class MailTestPortalNoPartner(models.Model):
  20. """ A model inheriting from portal, but without any partner field """
  21. _description = 'Chatter Model for Portal (no partner field)'
  22. _name = 'mail.test.portal.no.partner'
  23. _inherit = [
  24. 'mail.thread',
  25. 'portal.mixin',
  26. ]
  27. name = fields.Char()
  28. def _compute_access_url(self):
  29. self.access_url = False
  30. for record in self.filtered('id'):
  31. record.access_url = '/my/test_portal_no_partner/%s' % self.id
  32. class MailTestRating(models.Model):
  33. """ A model inheriting from mail.thread with some fields used for SMS
  34. gateway, like a partner, a specific mobile phone, ... """
  35. _description = 'Rating Model (ticket-like)'
  36. _name = 'mail.test.rating'
  37. _inherit = [
  38. 'mail.thread',
  39. 'mail.activity.mixin',
  40. 'rating.mixin',
  41. 'portal.mixin',
  42. ]
  43. _mailing_enabled = True
  44. _order = 'name asc, id asc'
  45. name = fields.Char()
  46. subject = fields.Char()
  47. company_id = fields.Many2one('res.company', 'Company')
  48. customer_id = fields.Many2one('res.partner', 'Customer')
  49. email_from = fields.Char(compute='_compute_email_from', precompute=True, readonly=False, store=True)
  50. mobile_nbr = fields.Char(compute='_compute_mobile_nbr', precompute=True, readonly=False, store=True)
  51. phone_nbr = fields.Char(compute='_compute_phone_nbr', precompute=True, readonly=False, store=True)
  52. user_id = fields.Many2one('res.users', 'Responsible', tracking=1)
  53. @api.depends('customer_id')
  54. def _compute_email_from(self):
  55. for rating in self:
  56. if rating.customer_id.email_normalized:
  57. rating.email_from = rating.customer_id.email_normalized
  58. elif not rating.email_from:
  59. rating.email_from = False
  60. @api.depends('customer_id')
  61. def _compute_mobile_nbr(self):
  62. for rating in self:
  63. if rating.customer_id.mobile:
  64. rating.mobile_nbr = rating.customer_id.mobile
  65. elif not rating.mobile_nbr:
  66. rating.mobile_nbr = False
  67. @api.depends('customer_id')
  68. def _compute_phone_nbr(self):
  69. for rating in self:
  70. if rating.customer_id.phone:
  71. rating.phone_nbr = rating.customer_id.phone
  72. elif not rating.phone_nbr:
  73. rating.phone_nbr = False
  74. def _mail_get_partner_fields(self):
  75. return ['customer_id']
  76. def _rating_apply_get_default_subtype_id(self):
  77. return self.env['ir.model.data']._xmlid_to_res_id("test_mail_full.mt_mail_test_rating_rating_done")
  78. def _rating_get_partner(self):
  79. return self.customer_id