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.

58 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Vincent Renaville,Damien Crier
  5. # Copyright 2014-2015 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api, _
  22. class PartnerPrintActivity(models.TransientModel):
  23. _name = 'partner.print.activity'
  24. _description = 'Partner printing activity'
  25. @api.model
  26. def _get_partner_ids(self):
  27. context = self.env.context
  28. if context.get('active_model') != 'res.partner':
  29. return False
  30. return context.get('active_ids', False)
  31. partner_information = fields.Boolean(string='Print partner address',
  32. default=True)
  33. partner_address_information = fields.Boolean(
  34. string='Print partner contacts',
  35. default=True)
  36. partner_ids = fields.Many2many(comodel_name='res.partner',
  37. string='Partner ids',
  38. default=_get_partner_ids)
  39. user_id = fields.Many2one(comodel_name='res.users', string='User',
  40. required=False, default=1)
  41. @api.multi
  42. def print_report(self):
  43. self.ensure_one()
  44. if not self.partner_ids:
  45. raise api.Warning(_('No partner selected'))
  46. report_name = 'partner_activity_report_base.'\
  47. 'report_partner_activity_qweb'
  48. report_obj = self.env['report'].with_context(
  49. active_ids=self.id
  50. )
  51. return report_obj.get_action(self, report_name)