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.
 
 
 
 

76 lines
3.0 KiB

# -*- encoding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2010 - 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp.osv import orm
class PartnerAgedStatement(orm.Model):
_inherit = 'res.partner'
def action_aged_statement_send(self, cr, uid, ids, context=None):
# This function opens a window to compose an email,
# with the partner aged statemen template message loaded by default
# This option should only be used for a single id at a time.
assert len(ids) == 1
ir_model_data = self.pool.get('ir.model.data')
try:
template_id = ir_model_data.get_object_reference(
cr, uid,
'account_partner_aged_statement_webkit',
'email_template_aged_statement')[1]
except ValueError:
template_id = False
try:
compose_form_id = ir_model_data.get_object_reference(
cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
# When doing search with related company, it creates a bug saying
# the xx id doesn't exist in mail.message.
# The default_parent_id is used by mail.compose.message model
# to get the message_id. It must be false when doing search with
# related company
if 'default_parent_id' in context:
del context['default_parent_id']
ctx = dict(context)
ctx.update({
'default_model': 'res.partner',
'default_res_id': ids[0],
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment',
})
# Full explanation of this return is here :
# http://stackoverflow.com/questions/12634031
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}