Sélectionner une révision Git
scop_bordereau_validate_confirm.py 2,04 Kio
# © 2021 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import models, api, fields, _
from odoo.exceptions import UserError
class ScopBordereauValidate(models.TransientModel):
"""
This wizard will validate all the selected bordereaux
"""
_name = "scop.bordereau.validate"
_description = "Valider les bordereaux sélectionnés"
@api.model
def default_get(self, fields):
res = super(ScopBordereauValidate, self).default_get(fields)
template_id = self.env.ref(
'cgscop_cotisation_cg.email_template_cotisation_cg')
res.update({
'subject': template_id.subject,
'body_html': template_id.body_html,
})
return res
subject = fields.Char('Objet:', translate=True, sanitize=False)
body_html = fields.Html('Corps du mail:', translate=True, sanitize=False)
@api.multi
def bordereau_validate(self):
context = dict(self._context or {})
active_ids = context.get('active_ids', []) or []
bordereau_ids = self.env['scop.bordereau'].browse(active_ids)
not_new_bordereau = bordereau_ids.filtered(
lambda b: b.state != 'new')
if not_new_bordereau:
raise UserError(_("Impossible de valider un bordereau qui "
"n'est pas à l'état de brouillon"))
else:
template_id = self.env.ref(
'cgscop_cotisation_cg.email_template_cotisation_cg')
mail_compose_message_id = self.env['mail.compose.message'].create({
'subject': self.subject,
'body': self.body_html,
'model': 'scop.bordereau',
'email_from': template_id.email_from,
'reply_to': template_id.reply_to,
'auto_delete': False,
'composition_mode': 'mass_mail',
})
bordereau_ids.validate_bordereau_multi(mail_compose_message_id.id)
return {'type': 'ir.actions.act_window_close'}