mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-27 01:12:01 +02:00
Initial commit: Hr packages
This commit is contained in:
commit
62531cd146
2820 changed files with 1432848 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import applicant_refuse_reason
|
||||
from . import applicant_send_mail
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ApplicantGetRefuseReason(models.TransientModel):
|
||||
_name = 'applicant.get.refuse.reason'
|
||||
_description = 'Get Refuse Reason'
|
||||
|
||||
refuse_reason_id = fields.Many2one('hr.applicant.refuse.reason', 'Refuse Reason', required=True)
|
||||
applicant_ids = fields.Many2many('hr.applicant')
|
||||
send_mail = fields.Boolean("Send Email", compute='_compute_send_mail', store=True, readonly=False)
|
||||
template_id = fields.Many2one('mail.template', string='Email Template',
|
||||
compute='_compute_send_mail', store=True, readonly=False,
|
||||
domain="[('model', '=', 'hr.applicant')]")
|
||||
applicant_without_email = fields.Text(compute='_compute_applicant_without_email',
|
||||
string='Applicant(s) not having email')
|
||||
|
||||
@api.depends('refuse_reason_id')
|
||||
def _compute_send_mail(self):
|
||||
for wizard in self:
|
||||
template = wizard.refuse_reason_id.template_id
|
||||
wizard.send_mail = bool(template)
|
||||
wizard.template_id = template
|
||||
|
||||
@api.depends('applicant_ids', 'send_mail')
|
||||
def _compute_applicant_without_email(self):
|
||||
for wizard in self:
|
||||
applicants = wizard.applicant_ids.filtered(lambda x: not x.email_from and not x.partner_id.email)
|
||||
if applicants and wizard.send_mail:
|
||||
wizard.applicant_without_email = "%s\n%s" % (
|
||||
_("The email will not be sent to the following applicant(s) as they don't have email address."),
|
||||
"\n".join([i.partner_name or i.name for i in applicants])
|
||||
)
|
||||
else:
|
||||
wizard.applicant_without_email = False
|
||||
|
||||
def action_refuse_reason_apply(self):
|
||||
if self.send_mail:
|
||||
if not self.template_id:
|
||||
raise UserError(_("Email template must be selected to send a mail"))
|
||||
if not self.applicant_ids.filtered(lambda x: x.email_from or x.partner_id.email):
|
||||
raise UserError(_("Email of the applicant is not set, email won't be sent."))
|
||||
self.applicant_ids.write({'refuse_reason_id': self.refuse_reason_id.id, 'active': False})
|
||||
if self.send_mail:
|
||||
applicants = self.applicant_ids.filtered(lambda x: x.email_from or x.partner_id.email)
|
||||
applicants.with_context(active_test=True).message_post_with_template(self.template_id.id, **{
|
||||
'auto_delete_message': True,
|
||||
'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_note'),
|
||||
'email_layout_xmlid': 'mail.mail_notification_light'
|
||||
})
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="applicant_get_refuse_reason_view_form" model="ir.ui.view">
|
||||
<field name="name">applicant.get.refuse.reason.form</field>
|
||||
<field name="model">applicant.get.refuse.reason</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Refuse Reason">
|
||||
<group col="1">
|
||||
<field name="refuse_reason_id" widget="selection_badge" options="{'horizontal': true, 'no_create': True, 'no_open': True}"/>
|
||||
<field name="send_mail" attrs="{'invisible': [('refuse_reason_id', '=', False)]}"/>
|
||||
<field name="template_id" attrs="{'invisible': [('send_mail', '=', False)], 'required': [('send_mail', '=', True)]}" />
|
||||
<field name="applicant_ids" invisible="1"/>
|
||||
</group>
|
||||
<div class="alert alert-danger" role="alert" attrs="{'invisible': [('applicant_without_email', '=', False)]}">
|
||||
<field name="applicant_without_email" class="mr4"/>
|
||||
</div>
|
||||
<footer>
|
||||
<button name="action_refuse_reason_apply" string="Refuse" type="object" class="btn-primary" data-hotkey="q"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="applicant_get_refuse_reason_action" model="ir.actions.act_window">
|
||||
<field name="name">Refuse Reason</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">applicant.get.refuse.reason</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="applicant_get_refuse_reason_view_form"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class ApplicantSendMail(models.TransientModel):
|
||||
_name = 'applicant.send.mail'
|
||||
_inherit = 'mail.composer.mixin'
|
||||
_description = 'Send mails to applicants'
|
||||
|
||||
applicant_ids = fields.Many2many('hr.applicant', string='Applications', required=True)
|
||||
author_id = fields.Many2one('res.partner', 'Author', required=True, default=lambda self: self.env.user.partner_id.id)
|
||||
|
||||
@api.depends('subject')
|
||||
def _compute_render_model(self):
|
||||
self.render_model = 'hr.applicant'
|
||||
|
||||
def action_send(self):
|
||||
self.ensure_one()
|
||||
|
||||
without_emails = self.applicant_ids.filtered(lambda a: not a.email_from or (a.partner_id and not a.partner_id.email))
|
||||
if without_emails:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'type': 'danger',
|
||||
'message': _("The following applicants are missing an email address: %s.", ', '.join(without_emails.mapped(lambda a: a.partner_name or a.name))),
|
||||
}
|
||||
}
|
||||
|
||||
if self.template_id:
|
||||
subjects = self._render_field('subject', res_ids=self.applicant_ids.ids)
|
||||
bodies = self._render_field('body', res_ids=self.applicant_ids.ids)
|
||||
else:
|
||||
subjects = {applicant.id: self.subject for applicant in self.applicant_ids}
|
||||
bodies = {applicant.id: self.body for applicant in self.applicant_ids}
|
||||
|
||||
for applicant in self.applicant_ids:
|
||||
if not applicant.partner_id:
|
||||
applicant.partner_id = self.env['res.partner'].create({
|
||||
'is_company': False,
|
||||
'type': 'private',
|
||||
'name': applicant.partner_name,
|
||||
'email': applicant.email_from,
|
||||
'phone': applicant.partner_phone,
|
||||
'mobile': applicant.partner_mobile,
|
||||
})
|
||||
|
||||
applicant.message_post(
|
||||
subject=subjects[applicant.id],
|
||||
body=bodies[applicant.id],
|
||||
message_type='comment',
|
||||
email_from=self.author_id.email,
|
||||
email_layout_xmlid='mail.mail_notification_light',
|
||||
partner_ids=applicant.partner_id.ids,
|
||||
)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="applicant_send_mail_view_form" model="ir.ui.view">
|
||||
<field name="model">applicant.send.mail</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="author_id" invisible="1"/>
|
||||
<group>
|
||||
<field name="subject" required="1"/>
|
||||
<field name="applicant_ids" widget="many2many_tags" context="{'show_partner_name': 1}"/>
|
||||
</group>
|
||||
<field name="body" nolabel="1" class="oe-bordered-editor"
|
||||
placeholder="Write your message here..."
|
||||
options="{'style-inline': true, 'codeview': true, 'dynamic_placeholder': true}"
|
||||
force_save="1"/>
|
||||
<footer>
|
||||
<button name="action_send" string="Send" type="object" class="btn-primary" data-hotkey="q"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue