19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:28 +01:00
parent ff721d030e
commit 7721452493
1826 changed files with 124775 additions and 274114 deletions

View file

@ -3,23 +3,21 @@ from odoo import models, fields, api, _
from odoo.exceptions import UserError
class QrInvoiceWizard(models.TransientModel):
class L10n_ChQr_InvoiceWizard(models.TransientModel):
'''
Wizard :
When multiple invoices are selected to be printed in the QR-Iban format,
this wizard will appear if one or more invoice(s) could not be QR-printed (wrong format...)
The user will then be able to print the invoices (in the format available, priority : QR --> ISR --> normal)
or to see a list of the non-QR/ISR invoices.
The non-QR/ISR invoices will have a note logged in their chatter, detailing the reason of the failure.
The user will then be able to print the invoices that couldn't be printed in the QR format in the normal format, or
to see a list of those.
The non-QR invoices will have a note logged in their chatter, detailing the reason of the failure.
'''
_name = 'l10n_ch.qr_invoice.wizard'
_description = 'Handles problems occurring while creating multiple QR-invoices at once'
nb_qr_inv = fields.Integer(readonly=True)
nb_isr_inv = fields.Integer(readonly=True)
nb_classic_inv = fields.Integer(readonly=True)
qr_inv_text = fields.Text(readonly=True)
isr_inv_text = fields.Text(readonly=True)
classic_inv_text = fields.Text(readonly=True)
@api.model
@ -34,12 +32,12 @@ class QrInvoiceWizard(models.TransientModel):
return _("No invoice could be printed in the %s format.", inv_format)
if nb_inv == 1:
return _("One invoice could be printed in the %s format.", inv_format)
return _("%s invoices could be printed in the %s format.", nb_inv, inv_format)
return _("%(amount)s invoices could be printed in the %(format)s format.", amount=nb_inv, format=inv_format)
if not self._context.get('active_ids'):
if not self.env.context.get('active_ids'):
raise UserError(_("No invoice was found to be printed."))
invoices = self.env['account.move'].browse(self._context['active_ids'])
invoices = self.env['account.move'].browse(self.env.context['active_ids'])
companies = invoices.company_id
if len(companies) != 1 or companies[0].country_code != 'CH':
raise UserError(_("All selected invoices must belong to the same Switzerland company"))
@ -48,12 +46,9 @@ class QrInvoiceWizard(models.TransientModel):
dispatched_invoices = invoices._l10n_ch_dispatch_invoices_to_print()
results.update({
'nb_qr_inv': len(dispatched_invoices['qr']),
'nb_isr_inv': len(dispatched_invoices['isr']),
'nb_classic_inv': len(dispatched_invoices['classic']),
'qr_inv_text': determine_invoices_text(nb_inv=len(dispatched_invoices['qr']), inv_format="QR"),
'isr_inv_text': determine_invoices_text(nb_inv=len(dispatched_invoices['isr']), inv_format="ISR"),
'classic_inv_text': determine_invoices_text(nb_inv=len(dispatched_invoices['classic']),
inv_format="classic"),
'classic_inv_text': determine_invoices_text(nb_inv=len(dispatched_invoices['classic']), inv_format="classic"),
})
return results
@ -66,21 +61,18 @@ class QrInvoiceWizard(models.TransientModel):
def action_view_faulty_invoices(self):
'''
Open a list view of all the invoices that could not be printed in the QR nor the ISR format.
Open a list view of all the invoices that could not be printed in the QR format.
'''
# Prints the error stopping the invoice from being QR-printed in the invoice's chatter.
invoices = self.env['account.move'].browse(self._context['active_ids'])
invoices = self.env['account.move'].browse(self.env.context['active_ids'])
dispatched_invoices = invoices._l10n_ch_dispatch_invoices_to_print()
faulty_invoices = dispatched_invoices['classic']
# Log a message inside the chatter explaining why the invoice is faulty.
for inv in faulty_invoices:
try:
# The error potentially raised in the following function helps create the wizard's message.
inv.partner_bank_id._eligible_for_qr_code('ch_qr', inv.partner_id, inv.currency_id, raises_error=True)
except UserError as e:
inv.message_post(body=e.name, message_type="comment")
error_msg = inv.partner_bank_id._get_error_messages_for_qr('ch_qr', inv.partner_id, inv.currency_id)
if error_msg:
inv.message_post(body=error_msg, message_type="comment")
action_vals = {
'name': _("Invalid Invoices"),
'type': 'ir.actions.act_window',
@ -94,7 +86,7 @@ class QrInvoiceWizard(models.TransientModel):
})
else:
action_vals.update({
'view_mode': 'tree',
'view_mode': 'list',
'domain': [('id', 'in', faulty_invoices.ids)],
})
return action_vals

View file

@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
from odoo import api, models
from odoo import api, models, fields
class SwissSetupBarBankConfigWizard(models.TransientModel):
class AccountSetupBankManualConfig(models.TransientModel):
_inherit = 'account.setup.bank.manual.config'
@api.onchange('acc_number')
@ -14,3 +13,10 @@ class SwissSetupBarBankConfigWizard(models.TransientModel):
self.res_partner_bank_id.acc_number = self.acc_number
self.res_partner_bank_id._compute_l10n_ch_qr_iban()
self.l10n_ch_qr_iban = self.res_partner_bank_id.l10n_ch_qr_iban
l10n_ch_display_qr_bank_options = fields.Boolean(compute='_compute_l10n_ch_display_qr_bank_options')
@api.depends('partner_id', 'company_id')
def _compute_l10n_ch_display_qr_bank_options(self):
for wizard in self:
wizard.l10n_ch_display_qr_bank_options = wizard.res_partner_bank_id.l10n_ch_display_qr_bank_options