Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] l10n_ar_account_withholding: certificados de retencion en envio de mails #986

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions l10n_ar_account_withholding/models/mail_compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,29 @@
class MailComposeMessage(models.TransientModel):
_inherit = "mail.compose.message"

# TODO falta adaptar
def _onchange_template_id(self, template_id, composition_mode, model, res_id):
values = super()._onchange_template_id(
template_id, composition_mode, model, res_id)
if template_id and model == 'account.payment':
payment = self.env[model].browse(res_id)
if payment.partner_type != 'supplier':
return values
report = self.env.ref('l10n_ar_account_withholding.action_report_withholding_certificate',
raise_if_not_found=False)
if not report:
return values
attachment_ids = []
for payment in payment.payment_ids.filtered(lambda p: p.payment_method_code == 'withholding'):
report_name = safe_eval.safe_eval(report.print_report_name, {'object': payment})
result, format = self.env['ir.actions.report']._render(report.report_name, payment.ids)
file = base64.b64encode(result)
data_attach = {
'name': report_name,
'datas': file,
'res_model': 'mail.compose.message',
'res_id': 0,
'type': 'binary',
}
attachment_ids.append(self.env['ir.attachment'].create(data_attach).id)
if values.get('value', False) and values['value'].get('attachment_ids', []) or attachment_ids:
values_attachment_ids = values['value'].get('attachment_ids', False) and \
values['value']['attachment_ids'][0][2] or []
values['value']['attachment_ids'] = [(6, 0, values_attachment_ids + attachment_ids)]
def _compute_attachment_ids(self):
""" Extendemos el método original para que se pueda previsualizar en el envío de mails de pagos el/los archivos de retenciones. """
super()._compute_attachment_ids()
for composer in self:
res_ids = composer._evaluate_res_ids() or [0]
Copy link
Contributor Author

@jue-adhoc jue-adhoc Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ver comentario del PR sobre caso de envío masivo de emails, ese es el caso en que res_ids va a ser mayor a 1, y habría que ver de implementar la funcionalidad de que los attachments se agreguen a cada email en el momento de enviarse, pero dentro del composer no debe mostarse ninguno

if composer.model == 'account.payment' and composer.template_id and len(res_ids) == 1:
payment = self.env[composer.model].browse(res_ids)
if payment.partner_type != 'supplier':
return

return values
report = self.env.ref('l10n_ar_withholding_ux.action_report_withholding_certificate',
raise_if_not_found=False)
if not report:
return
for withholding in payment.l10n_ar_withholding_line_ids:
report_name = safe_eval.safe_eval(report.print_report_name, {'object': withholding})
result, _ = self.env['ir.actions.report']._render(report.report_name, withholding.ids)
file = base64.b64encode(result)
data_attach = {
'name': report_name,
'datas': file,
'res_model': 'mail.compose.message',
'res_id': 0,
'type': 'binary',
}
composer.attachment_ids += self.env['ir.attachment'].create(data_attach)