Fix two issues linked to payment methods and their journal link. SEPA Credit Transfer was marked as only available on EUR journals, but from what we have been told, and we have seen, it should also be made available for other currencies (CHF/SEK). So we are changing the rule used to determine if SEPA Credit Transfer is available on a journal to allow to use it on journals using CHF or SEK as a currency. There is another issue, where the filtering is done differently at the journal creation and when the user add the payment method manually in the lists. The filter rules were not respected at the journal creation, which would lead to incorrect default inbound and outbound payment method list. For example, a new journal would have the company currency (let's say, USD) but still have SEPA Credit Transfer (EUR,CHF,SEK) added on it by default while it should not be available there. opw-2777522 X-original-commit: 0ad8faf3bfc7b28e5668c3445fcc06c24ad98354 [FIX] account_*: payment method journal filter Fix two issues linked to payment methods and their journal link. SEPA Credit Transfer was marked as only available on EUR journals, but from what we have been told, and we have seen, it should also be made available for other currencies (CHF/SEK). So we are changing the rule used to determine if SEPA Credit Transfer is available on a journal to allow to use it on journals using CHF or SEK as a currency. There is another issue, where the filtering is done differently at the journal creation and when the user add the payment method manually in the lists. The filter rules were not respected at the journal creation, which would lead to incorrect default inbound and outbound payment method list. For example, a new journal would have the company currency (let's say, USD) but still have SEPA Credit Transfer (EUR,CHF,SEK) added on it by default while it should not be available there. opw-2777522 closes odoo/odoo#88677 X-original-commit: e2cd91ad8339f73b2547bc839e675443528f3adf Related: odoo/enterprise#26172 Signed-off-by: Florian Gilbert <flg@odoo.com>
105 lines
4.1 KiB
Python
105 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import re
|
|
from odoo import models, fields, api, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class AccountJournal(models.Model):
|
|
_inherit = "account.journal"
|
|
|
|
def _default_outbound_payment_methods(self):
|
|
res = super()._default_outbound_payment_methods()
|
|
if self._is_payment_method_available('check_printing'):
|
|
res |= self.env.ref('account_check_printing.account_payment_method_check')
|
|
return res
|
|
|
|
check_manual_sequencing = fields.Boolean(
|
|
string='Manual Numbering',
|
|
default=False,
|
|
help="Check this option if your pre-printed checks are not numbered.",
|
|
)
|
|
check_sequence_id = fields.Many2one(
|
|
comodel_name='ir.sequence',
|
|
string='Check Sequence',
|
|
readonly=True,
|
|
copy=False,
|
|
help="Checks numbering sequence.",
|
|
)
|
|
check_next_number = fields.Char(
|
|
string='Next Check Number',
|
|
compute='_compute_check_next_number',
|
|
inverse='_inverse_check_next_number',
|
|
help="Sequence number of the next printed check.",
|
|
)
|
|
|
|
@api.depends('check_manual_sequencing')
|
|
def _compute_check_next_number(self):
|
|
for journal in self:
|
|
sequence = journal.check_sequence_id
|
|
if sequence:
|
|
journal.check_next_number = sequence.get_next_char(sequence.number_next_actual)
|
|
else:
|
|
journal.check_next_number = 1
|
|
|
|
def _inverse_check_next_number(self):
|
|
for journal in self:
|
|
if journal.check_next_number and not re.match(r'^[0-9]+$', journal.check_next_number):
|
|
raise ValidationError(_('Next Check Number should only contains numbers.'))
|
|
if int(journal.check_next_number) < journal.check_sequence_id.number_next_actual:
|
|
raise ValidationError(_(
|
|
"The last check number was %s. In order to avoid a check being rejected "
|
|
"by the bank, you can only use a greater number.",
|
|
journal.check_sequence_id.number_next_actual
|
|
))
|
|
if journal.check_sequence_id:
|
|
journal.check_sequence_id.sudo().number_next_actual = int(journal.check_next_number)
|
|
journal.check_sequence_id.sudo().padding = len(journal.check_next_number)
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
journals = super().create(vals_list)
|
|
journals.filtered(lambda j: not j.check_sequence_id)._create_check_sequence()
|
|
return journals
|
|
|
|
def _create_check_sequence(self):
|
|
""" Create a check sequence for the journal """
|
|
for journal in self:
|
|
journal.check_sequence_id = self.env['ir.sequence'].sudo().create({
|
|
'name': journal.name + _(" : Check Number Sequence"),
|
|
'implementation': 'no_gap',
|
|
'padding': 5,
|
|
'number_increment': 1,
|
|
'company_id': journal.company_id.id,
|
|
})
|
|
|
|
def get_journal_dashboard_datas(self):
|
|
domain_checks_to_print = [
|
|
('journal_id', '=', self.id),
|
|
('payment_method_line_id.code', '=', 'check_printing'),
|
|
('state', '=', 'posted'),
|
|
('is_move_sent','=', False),
|
|
]
|
|
return dict(
|
|
super(AccountJournal, self).get_journal_dashboard_datas(),
|
|
num_checks_to_print=self.env['account.payment'].search_count(domain_checks_to_print),
|
|
)
|
|
|
|
def action_checks_to_print(self):
|
|
payment_method_line = self.outbound_payment_method_line_ids.filtered(lambda l: l.code == 'check_printing')
|
|
return {
|
|
'name': _('Checks to Print'),
|
|
'type': 'ir.actions.act_window',
|
|
'view_mode': 'list,form,graph',
|
|
'res_model': 'account.payment',
|
|
'context': dict(
|
|
self.env.context,
|
|
search_default_checks_to_send=1,
|
|
journal_id=self.id,
|
|
default_journal_id=self.id,
|
|
default_payment_type='outbound',
|
|
default_payment_method_line_id=payment_method_line.id,
|
|
),
|
|
}
|