mirror of
https://gitlab.com/flectra-community/l10n-switzerland-flectra.git
synced 2024-12-23 04:41:45 +00:00
✨ Settings to define if ISR and QR should be added to email template, and also if it should only be done when invoice is not paid
->l10n_ch_report_optional
This commit is contained in:
parent
681a0990eb
commit
c10ba87c3f
4
l10n_ch_report_optional/__init__.py
Normal file
4
l10n_ch_report_optional/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
19
l10n_ch_report_optional/__manifest__.py
Normal file
19
l10n_ch_report_optional/__manifest__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
# Main contributor: Nicolas Bessi. Camptocamp SA
|
||||
# Financial contributors: Hasa SA, Open Net SA,
|
||||
# Prisme Solutions Informatique SA, Quod SA
|
||||
# Translation contributors: brain-tec AG, Agile Business Group
|
||||
{
|
||||
'name': "Switzerland - Accounting Optional Reports as Attachments",
|
||||
'description': """
|
||||
Add some parameters to define if ISR or QR Bill should be added automatically
|
||||
""",
|
||||
'version': '1.0.1.0',
|
||||
'category': 'Accounting',
|
||||
'depends': ['l10n_ch'],
|
||||
'data': [
|
||||
'views/res_config_settings_views.xml',
|
||||
],
|
||||
'license': 'LGPL-3',
|
||||
}
|
6
l10n_ch_report_optional/models/__init__.py
Normal file
6
l10n_ch_report_optional/models/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import res_config_settings
|
||||
from . import mail_template
|
||||
from . import res_company
|
56
l10n_ch_report_optional/models/mail_template.py
Normal file
56
l10n_ch_report_optional/models/mail_template.py
Normal file
@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import base64
|
||||
|
||||
from flectra import api, models
|
||||
from flectra.addons.l10n_ch.models.mail_template import MailTemplate
|
||||
|
||||
|
||||
def generate_email(self, res_ids, fields):
|
||||
""" Method overridden in order to add an attachment containing the ISR
|
||||
to the draft message when opening the 'send by mail' wizard on an invoice.
|
||||
This attachment generation will only occur if all the required data are
|
||||
present on the invoice. Otherwise, no ISR attachment will be created, and
|
||||
the mail will only contain the invoice (as defined in the mother method).
|
||||
"""
|
||||
result = super(MailTemplate, self).generate_email(res_ids, fields)
|
||||
if self.model != 'account.move':
|
||||
return result
|
||||
|
||||
multi_mode = True
|
||||
if isinstance(res_ids, int):
|
||||
res_ids = [res_ids]
|
||||
multi_mode = False
|
||||
|
||||
if self.model == 'account.move':
|
||||
for record in self.env[self.model].browse(res_ids):
|
||||
inv_print_name = self._render_field('report_name', record.ids, compute_lang=True)[record.id]
|
||||
new_attachments = []
|
||||
if not self.env.company.l10n_ignore_qr_when_reconciled or record.payment_state != 'paid':
|
||||
if record.l10n_ch_isr_valid and self.env.company.l10n_add_isr_pdf:
|
||||
# We add an attachment containing the ISR
|
||||
isr_report_name = 'ISR-' + inv_print_name + '.pdf'
|
||||
isr_pdf = self.env.ref('l10n_ch.l10n_ch_isr_report')._render_qweb_pdf(record.ids)[0]
|
||||
isr_pdf = base64.b64encode(isr_pdf)
|
||||
new_attachments.append((isr_report_name, isr_pdf))
|
||||
|
||||
if record.partner_bank_id._eligible_for_qr_code('ch_qr', record.partner_id, record.currency_id) and self.env.company.l10n_add_qr_pdf:
|
||||
# We add an attachment containing the QR-bill
|
||||
qr_report_name = 'QR-bill-' + inv_print_name + '.pdf'
|
||||
qr_pdf = self.env.ref('l10n_ch.l10n_ch_qr_report')._render_qweb_pdf(record.ids)[0]
|
||||
qr_pdf = base64.b64encode(qr_pdf)
|
||||
new_attachments.append((qr_report_name, qr_pdf))
|
||||
|
||||
record_dict = multi_mode and result[record.id] or result
|
||||
attachments_list = record_dict.get('attachments', False)
|
||||
if attachments_list:
|
||||
attachments_list.extend(new_attachments)
|
||||
else:
|
||||
record_dict['attachments'] = new_attachments
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# Patch / Override existing Method
|
||||
MailTemplate.generate_email = generate_email
|
19
l10n_ch_report_optional/models/res_company.py
Normal file
19
l10n_ch_report_optional/models/res_company.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from flectra import fields, models
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
l10n_add_isr_pdf = fields.Boolean(
|
||||
string='ISR-PDF',
|
||||
)
|
||||
l10n_add_qr_pdf = fields.Boolean(
|
||||
string='QR-PDF',
|
||||
)
|
||||
l10n_ignore_qr_when_reconciled = fields.Boolean(
|
||||
string='Ignore QR when reconciled',
|
||||
help='Do not add QR Bill when invoice is reconciled',
|
||||
)
|
21
l10n_ch_report_optional/models/res_config_settings.py
Normal file
21
l10n_ch_report_optional/models/res_config_settings.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from flectra import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
l10n_add_isr_pdf = fields.Boolean(
|
||||
related='company_id.l10n_add_isr_pdf',
|
||||
readonly=False,
|
||||
)
|
||||
l10n_add_qr_pdf = fields.Boolean(
|
||||
related='company_id.l10n_add_qr_pdf',
|
||||
readonly=False,
|
||||
)
|
||||
l10n_ignore_qr_when_reconciled = fields.Boolean(
|
||||
related='company_id.l10n_ignore_qr_when_reconciled',
|
||||
readonly=False,
|
||||
)
|
53
l10n_ch_report_optional/views/res_config_settings_views.xml
Normal file
53
l10n_ch_report_optional/views/res_config_settings_views.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<flectra>
|
||||
<data>
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.l10n.ch</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='pay_invoice_online_setting_container']" position="after">
|
||||
<h2>Send & Print: adds additional single pdf</h2>
|
||||
<div class="row mt16 o_settings_container" id="add_pdfs_in_invoice_online_setting_container">
|
||||
<div class="col-12 col-lg-6 o_setting_box"
|
||||
title="Add a single attachment with QR-code as pdf in your mail so your customers have a seperate paper for the invoice.">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="l10n_add_isr_pdf" class="oe_inline"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="l10n_add_isr_pdf"/>
|
||||
<div class="text-muted">
|
||||
Add ISR-Invoice in mail
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6 o_setting_box"
|
||||
title="Add a single attachment with QR-code as pdf in your mail so your customers have a seperate paper for the invoice.">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="l10n_add_qr_pdf" class="oe_inline"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="l10n_add_qr_pdf"/>
|
||||
<div class="text-muted">
|
||||
Add QR-Invoice in mail
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6 o_setting_box"
|
||||
title="Do not add ISR or QR Invoice when invoice is already paid">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="l10n_ignore_qr_when_reconciled" class="oe_inline"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="l10n_ignore_qr_when_reconciled"/>
|
||||
<div class="text-muted">
|
||||
Only add ISR / QR Invoice when not yet paid
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</flectra>
|
Loading…
Reference in New Issue
Block a user