mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[FIX] Import exceptions.Warning as UserError.
This according to OCA guidelines. Also reformat README.rst to keep lines within limit.
This commit is contained in:
@@ -1,20 +1,35 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:alt: License: AGPL-3
|
||||
|
||||
Unique bank account numbers
|
||||
===========================
|
||||
|
||||
It can be desirable to be able to rely on a bank account number identifying exactly one partner. This module allows you to enforce this, so that an account number is unique in the system.
|
||||
It can be desirable to be able to rely on a bank account number identifying
|
||||
exactly one partner. This module allows you to enforce this, so that an
|
||||
account number is unique in the system.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
During installation, the module checks if your bank account numbers are unique already. If this is not the case, you won't be able to install the module until duplicates are fixed.
|
||||
During installation, the module checks if your bank account numbers are
|
||||
unique already. If this is not the case, you won't be able to install the
|
||||
module until duplicates are fixed.
|
||||
|
||||
The error message only shows the first few duplicates, in order to find all of them, use the following statement::
|
||||
The error message only shows the first few duplicates, in order to find all
|
||||
of them, use the following statement::
|
||||
|
||||
with res_partner_bank_sanitized as (select id, acc_number, regexp_replace(acc_number, '\W+', '', 'g') acc_number_sanitized from res_partner_bank),
|
||||
res_partner_bank_sanitized_grouped as (select array_agg(id) ids, acc_number_sanitized, count(*) amount from res_partner_bank_sanitized group by acc_number_sanitized)
|
||||
select * from res_partner_bank_sanitized_grouped where amount > 1;
|
||||
with res_partner_bank_sanitized as (
|
||||
select
|
||||
id, acc_number,
|
||||
regexp_replace(acc_number, '\W+', '', 'g') acc_number_sanitized
|
||||
from res_partner_bank
|
||||
),
|
||||
res_partner_bank_sanitized_grouped as (
|
||||
select
|
||||
array_agg(id) ids, acc_number_sanitized, count(*) amount
|
||||
from res_partner_bank_sanitized group by acc_number_sanitized
|
||||
)
|
||||
select * from res_partner_bank_sanitized_grouped where amount > 1;
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
# Copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -18,16 +18,16 @@
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
"name": "Unique bank account numbers",
|
||||
"version": "8.0.1.0.0",
|
||||
"author": "Therp BV,Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"category": "Accounting & Finance",
|
||||
"summary": "Enforce uniqueness on bank accounts",
|
||||
"depends": [
|
||||
'name': 'Unique bank account numbers',
|
||||
'version': '8.0.1.0.1',
|
||||
'author': 'Therp BV, Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Banking addons',
|
||||
'summary': 'Enforce uniqueness on bank accounts',
|
||||
'depends': [
|
||||
'account_bank_statement_import',
|
||||
],
|
||||
"post_init_hook": "post_init_hook",
|
||||
"auto_install": False,
|
||||
"installable": True,
|
||||
'post_init_hook': 'post_init_hook',
|
||||
'auto_install': False,
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp import _, SUPERUSER_ID, exceptions
|
||||
from openerp import _, SUPERUSER_ID
|
||||
from openerp.exceptions import Warning as UserError
|
||||
|
||||
|
||||
def post_init_hook(cr, pool):
|
||||
'''check if your constraint was actually inserted, raise otherwise'''
|
||||
"""check if your constraint was actually inserted, raise otherwise"""
|
||||
if not pool['ir.model.constraint'].search(cr, SUPERUSER_ID, [
|
||||
('name', '=', 'res_partner_bank_unique_number'),
|
||||
('model.model', '=', 'res.partner.bank'),
|
||||
@@ -51,4 +52,4 @@ def post_init_hook(cr, pool):
|
||||
max_account_numbers, '\n'.join(duplicates),
|
||||
max_account_numbers,
|
||||
)
|
||||
raise exceptions.Warning(message)
|
||||
raise UserError(message)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.tests.common import TransactionCase
|
||||
from openerp import exceptions
|
||||
from openerp.exceptions import Warning as UserError
|
||||
from ..hooks import post_init_hook
|
||||
|
||||
|
||||
@@ -38,5 +38,5 @@ class TestBaseBankAccountNumberUnique(TransactionCase):
|
||||
'acc_number': 'BE 1234 567 890',
|
||||
'state': 'bank',
|
||||
})
|
||||
with self.assertRaises(exceptions.Warning):
|
||||
with self.assertRaises(UserError):
|
||||
post_init_hook(self.cr, self.registry)
|
||||
|
||||
Reference in New Issue
Block a user