Merge pull request #509 from grindtildeath/10.0-add_account_type_inactive

[10.0][ADD] module account_type_inactive
This commit is contained in:
Yannick Vaucher
2017-07-14 10:40:08 +02:00
committed by GitHub
8 changed files with 193 additions and 0 deletions

View File

@@ -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
============
Installing the module will keep existing account types 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
<https://github.com/OCA/account-financial-tools/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Akim Juillerat <akim.juillerat@camptocamp.com>
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.

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -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,
}

View File

@@ -0,0 +1 @@
from . import account_type

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
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 used on %d '
'accounts.' % len(accounts)))

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -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)

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_type_form" model="ir.ui.view">
<field name="name">account.account.type.form.inherit</field>
<field name="model">account.account.type</field>
<field name="inherit_id" ref="account.view_account_type_form" />
<field name="arch" type="xml">
<field name="type" position="after">
<field name="active" />
</field>
</field>
</record>
</odoo>