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.

36 lines
955 B

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. import logging
  4. def getlogger(name):
  5. filename = 'test.log'
  6. logger = logging.getLogger(name)
  7. handler = logging.FileHandler(filename)
  8. formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s: %(message)s')
  9. handler.setFormatter(formatter)
  10. logger.addHandler(handler)
  11. logger.setLevel(logging.DEBUG)
  12. return logger
  13. logger = getlogger(__name__)
  14. class res_partner(models.Model):
  15. _inherit = 'res.partner'
  16. mails_from = fields.Integer(compute="_mails_from")
  17. mails_to = fields.Integer(compute="_mails_to")
  18. @api.one
  19. def _mails_from(self):
  20. for r in self:
  21. self.mails_from = self.env['mail.message'].sudo().search_count([('partner_ids', 'in', r.id)])
  22. @api.one
  23. def _mails_to(self):
  24. for r in self:
  25. self.mails_to = self.env['mail.message'].sudo().search_count([('author_id', '=', r.id)])