From df433a4dd781027ae2197024c16ec416cb0e5633 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 30 Jun 2017 14:56:03 +0200 Subject: [PATCH 1/5] Add module account_type_inactive --- account_type_inactive/README.rst | 64 ++++++++++++++++++++ account_type_inactive/__init__.py | 1 + account_type_inactive/__manifest__.py | 15 +++++ account_type_inactive/models/__init__.py | 1 + account_type_inactive/models/account_type.py | 12 ++++ account_type_inactive/views/account_type.xml | 13 ++++ 6 files changed, 106 insertions(+) create mode 100644 account_type_inactive/README.rst create mode 100644 account_type_inactive/__init__.py create mode 100644 account_type_inactive/__manifest__.py create mode 100644 account_type_inactive/models/__init__.py create mode 100644 account_type_inactive/models/account_type.py create mode 100644 account_type_inactive/views/account_type.xml diff --git a/account_type_inactive/README.rst b/account_type_inactive/README.rst new file mode 100644 index 000000000..7a0472c9a --- /dev/null +++ b/account_type_inactive/README.rst @@ -0,0 +1,64 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================== +Account Type Inactive +===================== + +This module extends the functionality of account module to allow you to flag +account types as active or inactive. + +Installation +============ + +Just install it. Existing account types will be flagged as active. + +Usage +===== + +On account types form view is an active checkbox to set account types you +don't need anymore as inactive. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/82/10.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Akim Juillerat + +Do not contact contributors directly about support or help with technical issues. + +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 https://odoo-community.org. diff --git a/account_type_inactive/__init__.py b/account_type_inactive/__init__.py new file mode 100644 index 000000000..9a7e03ede --- /dev/null +++ b/account_type_inactive/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/account_type_inactive/__manifest__.py b/account_type_inactive/__manifest__.py new file mode 100644 index 000000000..252f85847 --- /dev/null +++ b/account_type_inactive/__manifest__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + 'name': 'Account Type Inactive', + 'version': '10.0.1.0.0', + 'category': 'Accounting', + 'license': 'AGPL-3', + 'summary': "Allows to set account type to inactive", + 'author': "Camptocamp SA,Odoo Community Association (OCA)", + 'website': 'http://www.camptocamp.com/', + 'depends': ['account_type_menu'], + 'data': ['views/account_type.xml'], + 'installable': True, +} diff --git a/account_type_inactive/models/__init__.py b/account_type_inactive/models/__init__.py new file mode 100644 index 000000000..ba91da862 --- /dev/null +++ b/account_type_inactive/models/__init__.py @@ -0,0 +1 @@ +from . import account_type diff --git a/account_type_inactive/models/account_type.py b/account_type_inactive/models/account_type.py new file mode 100644 index 000000000..9f37e5180 --- /dev/null +++ b/account_type_inactive/models/account_type.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields + + +class AccountAccountType(models.Model): + + _inherit = 'account.account.type' + + active = fields.Boolean('Active', default=True) diff --git a/account_type_inactive/views/account_type.xml b/account_type_inactive/views/account_type.xml new file mode 100644 index 000000000..9ad4f94a8 --- /dev/null +++ b/account_type_inactive/views/account_type.xml @@ -0,0 +1,13 @@ + + + + account.account.type.form.inherit + account.account.type + + + + + + + + \ No newline at end of file From 206e602ae63e0ae87942d3c4d284205c4581d5ec Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 30 Jun 2017 15:08:02 +0200 Subject: [PATCH 2/5] Fix readme link --- account_type_inactive/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_type_inactive/README.rst b/account_type_inactive/README.rst index 7a0472c9a..8af50cf4c 100644 --- a/account_type_inactive/README.rst +++ b/account_type_inactive/README.rst @@ -29,7 +29,7 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues -`_. In case of trouble, please +`_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smash it by providing detailed and welcomed feedback. From d36177ae7e8700b6cabc050ec4e00bbe9cecb7b8 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 4 Jul 2017 13:56:42 +0200 Subject: [PATCH 3/5] Add constraint if account type is used on account.account --- account_type_inactive/models/account_type.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/account_type_inactive/models/account_type.py b/account_type_inactive/models/account_type.py index 9f37e5180..a479b2601 100644 --- a/account_type_inactive/models/account_type.py +++ b/account_type_inactive/models/account_type.py @@ -2,7 +2,8 @@ # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError class AccountAccountType(models.Model): @@ -10,3 +11,13 @@ class AccountAccountType(models.Model): _inherit = 'account.account.type' active = fields.Boolean('Active', default=True) + + @api.constrains('active') + def _check_account_moves(self): + if not self.active: + accounts = self.env['account.account'].search([ + ('user_type_id', '=', self.id)]) + if accounts: + raise ValidationError(_('You cannot inactive this account type' + ' as this type is is used on %d ' + 'accounts.' % len(accounts))) From ac100d980c6a520c4127921919053759c4fb998d Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 4 Jul 2017 13:56:59 +0200 Subject: [PATCH 4/5] Improve README install --- account_type_inactive/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_type_inactive/README.rst b/account_type_inactive/README.rst index 8af50cf4c..caf0d8cb0 100644 --- a/account_type_inactive/README.rst +++ b/account_type_inactive/README.rst @@ -12,7 +12,7 @@ account types as active or inactive. Installation ============ -Just install it. Existing account types will be flagged as active. +Installing the module will keep existing account types flagged as active. Usage ===== From 2b6f4718da0ab314429bc8af4e2f60bcd97bb0ad Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 4 Jul 2017 17:30:45 +0200 Subject: [PATCH 5/5] Add unittest, fix typo and eol --- account_type_inactive/__init__.py | 2 +- account_type_inactive/models/account_type.py | 2 +- account_type_inactive/tests/__init__.py | 3 + .../tests/test_account_type_inactive.py | 73 +++++++++++++++++++ account_type_inactive/views/account_type.xml | 2 +- 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 account_type_inactive/tests/__init__.py create mode 100644 account_type_inactive/tests/test_account_type_inactive.py diff --git a/account_type_inactive/__init__.py b/account_type_inactive/__init__.py index 9a7e03ede..0650744f6 100644 --- a/account_type_inactive/__init__.py +++ b/account_type_inactive/__init__.py @@ -1 +1 @@ -from . import models \ No newline at end of file +from . import models diff --git a/account_type_inactive/models/account_type.py b/account_type_inactive/models/account_type.py index a479b2601..f963c7b9a 100644 --- a/account_type_inactive/models/account_type.py +++ b/account_type_inactive/models/account_type.py @@ -19,5 +19,5 @@ class AccountAccountType(models.Model): ('user_type_id', '=', self.id)]) if accounts: raise ValidationError(_('You cannot inactive this account type' - ' as this type is is used on %d ' + ' as this type is used on %d ' 'accounts.' % len(accounts))) diff --git a/account_type_inactive/tests/__init__.py b/account_type_inactive/tests/__init__.py new file mode 100644 index 000000000..1fc122e1f --- /dev/null +++ b/account_type_inactive/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/account_type_inactive/tests/test_account_type_inactive.py b/account_type_inactive/tests/test_account_type_inactive.py new file mode 100644 index 000000000..1c3355449 --- /dev/null +++ b/account_type_inactive/tests/test_account_type_inactive.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError + + +class TestAccountTypeInactive(TransactionCase): + + def setUp(self): + super(TestAccountTypeInactive, self).setUp() + + self.income_type = self.env.ref('account.data_account_type_revenue') + self.payable_type = self.env.ref('account.data_account_type_payable') + self.custom_type = self.env['account.account.type'].create({ + 'name': 'Custom', + 'type': 'other' + }) + + self.journal = self.env['account.journal'].create({ + 'name': 'Test journal', + 'code': 'TEST', + 'type': 'sale', + }) + self.account_income = self.env['account.account'].create({ + 'name': 'Test income', + 'code': 'REV', + 'user_type_id': self.income_type.id + }) + self.account_payable = self.env['account.account'].create({ + 'name': 'Test payable', + 'code': 'PAY', + 'reconcile': True, + 'user_type_id': self.payable_type.id + }) + + def test_inactive(self): + + self.custom_type.active = False + # Check inactive account doesn't appear in search + active_types = self.env['account.account.type'].search([]) + self.assertNotIn(self.custom_type, active_types) + self.custom_type.active = True + + # Create move + self.env['account.move'].create({ + 'journal_id': self.journal.id, + 'line_ids': [(0, 0, { + 'name': 'debit payable', + 'debit': 20, + 'credit': 0, + 'account_id': self.account_payable.id, + }), (0, 0, { + 'name': 'credit income', + 'debit': 0, + 'credit': 20, + 'account_id': self.account_income.id, + })] + }) + + with self.assertRaises(ValidationError): + self.income_type.active = False + + income_accounts = self.env['account.account'].search([ + ('user_type_id', '=', self.income_type.id)]) + + income_accounts.write({ + 'user_type_id': self.custom_type.id + }) + + self.income_type.active = False + self.assertFalse(self.income_type.active) diff --git a/account_type_inactive/views/account_type.xml b/account_type_inactive/views/account_type.xml index 9ad4f94a8..12dc0df6a 100644 --- a/account_type_inactive/views/account_type.xml +++ b/account_type_inactive/views/account_type.xml @@ -10,4 +10,4 @@ - \ No newline at end of file +