Browse Source
Merge pull request #31 from hbrunn/8.0-no_uniqueness_in_sanitized_account_number
Merge pull request #31 from hbrunn/8.0-no_uniqueness_in_sanitized_account_number
8.0 no uniqueness in sanitized account numberpull/35/head
Pedro M. Baeza
10 years ago
19 changed files with 404 additions and 11 deletions
-
5account_bank_statement_import/__init__.py
-
3account_bank_statement_import/__openerp__.py
-
5account_bank_statement_import/models/__init__.py
-
0account_bank_statement_import/models/account_bank_statement_import.py
-
27account_bank_statement_import/models/account_config_settings.py
-
7account_bank_statement_import/models/res_partner_bank.py
-
0account_bank_statement_import/views/account_bank_statement_import_view.xml
-
17account_bank_statement_import/views/account_config_settings.xml
-
48base_bank_account_number_unique/README.rst
-
21base_bank_account_number_unique/__init__.py
-
33base_bank_account_number_unique/__openerp__.py
-
54base_bank_account_number_unique/hooks.py
-
36base_bank_account_number_unique/i18n/base_bank_account_number_unique.pot
-
38base_bank_account_number_unique/i18n/nl.po
-
20base_bank_account_number_unique/models/__init__.py
-
39base_bank_account_number_unique/models/res_partner_bank.py
-
BINbase_bank_account_number_unique/static/description/icon.png
-
20base_bank_account_number_unique/tests/__init__.py
-
42base_bank_account_number_unique/tests/test_base_bank_account_number_unique.py
@ -1,4 +1 @@ |
|||||
# -*- encoding: utf-8 -*- |
|
||||
|
|
||||
from . import res_partner_bank |
|
||||
from . import account_bank_statement_import |
|
||||
|
from . import models |
@ -0,0 +1,5 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
from . import res_partner_bank |
||||
|
from . import account_bank_statement_import |
||||
|
from . import account_config_settings |
@ -0,0 +1,27 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp import models, fields |
||||
|
|
||||
|
|
||||
|
class AccountConfigSettings(models.TransientModel): |
||||
|
_inherit = 'account.config.settings' |
||||
|
|
||||
|
module_base_bank_account_number_unique = fields.Boolean( |
||||
|
'Enforce unique account numbers on bank accounts') |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="view_account_config_settings" model="ir.ui.view"> |
||||
|
<field name="model">account.config.settings</field> |
||||
|
<field name="inherit_id" ref="account.view_account_config_settings" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<separator name="account_bank_statement_import" string="Bank statement import" /> |
||||
|
<group> |
||||
|
<field name="module_base_bank_account_number_unique" /> |
||||
|
</group> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,48 @@ |
|||||
|
.. 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. |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
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; |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback |
||||
|
`here <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20base_bank_account_number_unique%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Holger Brunn <hbrunn@therp.nl> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit http://odoo-community.org. |
@ -0,0 +1,21 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import models |
||||
|
from .hooks import post_init_hook |
@ -0,0 +1,33 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
"name": "Unique bank account numbers", |
||||
|
"version": "1.0", |
||||
|
"author": "Therp BV,Odoo Community Association (OCA)", |
||||
|
"license": "AGPL-3", |
||||
|
"category": "Accounting & Finance", |
||||
|
"summary": "Enforce uniqueness on bank accounts", |
||||
|
"depends": [ |
||||
|
'account_bank_statement_import', |
||||
|
], |
||||
|
"post_init_hook": "post_init_hook", |
||||
|
"auto_install": False, |
||||
|
"installable": True, |
||||
|
} |
@ -0,0 +1,54 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp import _, SUPERUSER_ID, exceptions |
||||
|
|
||||
|
|
||||
|
def post_init_hook(cr, pool): |
||||
|
'''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'), |
||||
|
]): |
||||
|
max_account_numbers = 10 |
||||
|
cr.execute( |
||||
|
""" |
||||
|
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 acc_number_sanitized from res_partner_bank_sanitized_grouped |
||||
|
where amount > 1 limit %s; |
||||
|
""", |
||||
|
(max_account_numbers,)) |
||||
|
duplicates = [acc_number for acc_number, in cr.fetchall()] |
||||
|
message = _( |
||||
|
"Module installation can't proceed as you have duplicate " |
||||
|
"account numbers in your system already. Please clean that up " |
||||
|
"and try again.\n" |
||||
|
"The following shows the first %d duplicate account numbers\n" |
||||
|
"%s\n" |
||||
|
"(if you see less than %d, those are the only duplicates)") % ( |
||||
|
max_account_numbers, '\n'.join(duplicates), |
||||
|
max_account_numbers, |
||||
|
) |
||||
|
raise exceptions.Warning(message) |
@ -0,0 +1,36 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * base_bank_account_number_unique |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 8.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2015-07-30 09:32+0000\n" |
||||
|
"PO-Revision-Date: 2015-07-30 09:32+0000\n" |
||||
|
"Last-Translator: <>\n" |
||||
|
"Language-Team: \n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: \n" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: sql_constraint:res.partner.bank:0 |
||||
|
msgid "Account Number must be unique" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: model:ir.model,name:base_bank_account_number_unique.model_res_partner_bank |
||||
|
msgid "Bank Accounts" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: code:addons/base_bank_account_number_unique/hooks.py:44 |
||||
|
#, python-format |
||||
|
msgid "Module installation can't proceed as you have duplicate account numbers in your system already. Please clean that up and try again.\n" |
||||
|
"The following shows the first %d duplicate account numbers\n" |
||||
|
"%s\n" |
||||
|
"(if you see less than %d, those are the only duplicates)" |
||||
|
msgstr "" |
||||
|
|
@ -0,0 +1,38 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * base_bank_account_number_unique |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 8.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2015-07-30 09:32+0000\n" |
||||
|
"PO-Revision-Date: 2015-07-30 09:32+0000\n" |
||||
|
"Last-Translator: <>\n" |
||||
|
"Language-Team: \n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: \n" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: sql_constraint:res.partner.bank:0 |
||||
|
msgid "Account Number must be unique" |
||||
|
msgstr "Rekeningnummer dient uniek te zijn" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: model:ir.model,name:base_bank_account_number_unique.model_res_partner_bank |
||||
|
msgid "Bank Accounts" |
||||
|
msgstr "Rekeningnummers" |
||||
|
|
||||
|
#. module: base_bank_account_number_unique |
||||
|
#: code:addons/base_bank_account_number_unique/hooks.py:44 |
||||
|
#, python-format |
||||
|
msgid "Module installation can't proceed as you have duplicate account numbers in your system already. Please clean that up and try again.\n" |
||||
|
"The following shows the first %d duplicate account numbers\n" |
||||
|
"%s\n" |
||||
|
"(if you see less than %d, those are the only duplicates)" |
||||
|
msgstr "De installatie kan niet door gaan omdat er al dubbele rekeningnummer in het systeem staan. Schoon dat op en probeer het opnieuw.\n" |
||||
|
"Er volgen de eerste %d dubbele rekeningnummers\n" |
||||
|
"%s\n" |
||||
|
"(indien er minder dan %d getoond worden, zijn er niet meer dubbele rekeningnummers)" |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import res_partner_bank |
@ -0,0 +1,39 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp import models |
||||
|
|
||||
|
|
||||
|
class ResPartnerBank(models.Model): |
||||
|
_inherit = 'res.partner.bank' |
||||
|
|
||||
|
def copy_data(self, cr, uid, id, default=None, context=None): |
||||
|
if default is None: |
||||
|
default = {} |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
if 'acc_number' not in default and 'default_acc_number' not in context: |
||||
|
default['acc_number'] = '' |
||||
|
return super(ResPartnerBank, self).copy_data( |
||||
|
cr, uid, id, default=default, context=context) |
||||
|
|
||||
|
_sql_constraints = [ |
||||
|
('unique_number', 'unique(sanitized_acc_number)', |
||||
|
'Account Number must be unique'), |
||||
|
] |
After Width: 80 | Height: 80 | Size: 428 B |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import test_base_bank_account_number_unique |
@ -0,0 +1,42 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This module 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 |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp.tests.common import TransactionCase |
||||
|
from openerp import exceptions |
||||
|
from ..hooks import post_init_hook |
||||
|
|
||||
|
|
||||
|
class TestBaseBankAccountNumberUnique(TransactionCase): |
||||
|
def test_base_bank_account_number_unique(self): |
||||
|
# drop our constraint, insert nonunique account numbers and see if |
||||
|
# the init hook catches this |
||||
|
self.env['ir.model.constraint'].search([ |
||||
|
('name', '=', 'res_partner_bank_unique_number'), |
||||
|
('model.model', '=', 'res.partner.bank'), |
||||
|
])._module_data_uninstall() |
||||
|
self.env['res.partner.bank'].create({ |
||||
|
'acc_number': 'BE1234567890', |
||||
|
'state': 'bank', |
||||
|
}) |
||||
|
self.env['res.partner.bank'].create({ |
||||
|
'acc_number': 'BE 1234 567 890', |
||||
|
'state': 'bank', |
||||
|
}) |
||||
|
with self.assertRaises(exceptions.Warning): |
||||
|
post_init_hook(self.cr, self.registry) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue