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.
 
 
 
 
 

75 lines
3.1 KiB

# -*- coding: utf-8 -*-
###################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2019-TODAY Cybrosys Technologies (<https://www.cybrosys.com>).
# Author: Anusha (<https://www.cybrosys.com>)
#
# This program is free software: you can modify
# it under the terms of the GNU Affero General Public License (AGPL) 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 <https://www.gnu.org/licenses/>.
#
###################################################################################
import logging
from odoo import models, _
_logger = logging.getLogger(__name__)
class HrPayslip(models.Model):
_inherit = 'hr.payslip'
def action_payslip_done(self):
"""Checking auto email option is set.if set email containing payslip details will be send on confirmation"""
res = super(HrPayslip, self).action_payslip_done()
if self.env['ir.config_parameter'].sudo().get_param('send_payslip_by_email'):
for payslip in self:
if payslip.employee_id.private_email:
template = self.env.ref('hr_payslip_monthly_report.email_template_payslip')
template.sudo().send_mail(payslip.id, force_send=True)
_logger.info("Payslip details for %s send by mail", payslip.employee_id.name)
return res
def action_payslip_send(self):
"""opens a window to compose an email,
with template message loaded by default"""
self.ensure_one()
ir_model_data = self.env['ir.model.data']
try:
template_id = ir_model_data.get_object_reference('hr_payslip_monthly_report',
'email_template_payslip')[1]
except ValueError:
template_id = False
try:
compose_form_id = ir_model_data.get_object_reference('mail',
'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
ctx = {
'default_model': 'hr.payslip',
'default_res_id': self.ids[0],
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment',
}
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}