Skip to content

Commit 8969f43

Browse files
committed
ADD account voucher cosntraint
1 parent f846969 commit 8969f43

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in module root
4+
# directory
5+
##############################################################################
6+
from . import models
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
5+
# All Rights Reserved.
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
{
22+
"name": "Account Voucher Constraints",
23+
'version': '8.0.0.0.0',
24+
'category': 'Localization/Argentina',
25+
'sequence': 14,
26+
'author': 'ADHOC SA',
27+
'website': 'www.adhoc.com.ar',
28+
'license': 'AGPL-3',
29+
'summary': '',
30+
"description": """
31+
Account Voucher Constraints
32+
===========================
33+
Add to cash/bank journals a field "voucher_amount_restriction" with values:
34+
* Can't be 0 (default): Voucher must have amount specified
35+
* Must be 0
36+
If you want to use voucher only for reconciliation we suggest you to create a
37+
journal called "Reconciliations" with option "Must be 0"
38+
""",
39+
"depends": [
40+
"account_voucher",
41+
],
42+
'external_dependencies': {
43+
},
44+
"data": [
45+
'views/account_journal_view.xml',
46+
],
47+
'demo': [
48+
],
49+
'test': [
50+
],
51+
'installable': True,
52+
'auto_install': False,
53+
'application': False,
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in module root
4+
# directory
5+
##############################################################################
6+
from . import account_journal
7+
from . import account_voucher
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in module root
4+
# directory
5+
##############################################################################
6+
from openerp import models, fields
7+
import logging
8+
_logger = logging.getLogger(__name__)
9+
10+
11+
class account_journal(models.Model):
12+
_inherit = "account.journal"
13+
14+
voucher_amount_restriction = fields.Selection([
15+
('cant_be_cero', "Can't be 0"),
16+
('must_be_cero', 'Must Be 0')],
17+
'Voucher Amount Restriction',
18+
default='cant_be_cero',
19+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
# For copyright and license notices, see __openerp__.py file in module root
4+
# directory
5+
##############################################################################
6+
from openerp import models, api, _
7+
from openerp.exceptions import Warning
8+
import logging
9+
_logger = logging.getLogger(__name__)
10+
11+
12+
class account_voucher(models.Model):
13+
_inherit = "account.voucher"
14+
15+
@api.constrains('state', 'journal_id', 'amount')
16+
def check_journal_amount_restriction(self):
17+
for voucher in self.filtered(lambda x: x.state == 'posted'):
18+
journal = self.journal_id
19+
if (
20+
journal.voucher_amount_restriction == 'cant_be_cero' and
21+
not voucher.amount
22+
):
23+
raise Warning(_(
24+
"On Journal '%s' amount can't be cero!\n"
25+
"* Voucher id: %i") % (journal.name, voucher.id))
26+
elif (
27+
journal.voucher_amount_restriction == 'must_be_cero' and
28+
voucher.amount
29+
):
30+
raise Warning(_(
31+
"On Journal '%s' amount must be cero!\n"
32+
"* Voucher id: %i") % (journal.name, voucher.id))
33+
return True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<openerp>
3+
<data>
4+
<record model='ir.ui.view' id='view_account_journal_form'>
5+
<field name='name'>account.journal.form</field>
6+
<field name="model">account.journal</field>
7+
<field name="inherit_id" ref="account.view_account_journal_form"/>
8+
<field name='arch' type='xml'>
9+
<field name="group_invoice_lines" position="after">
10+
<field name="voucher_amount_restriction"/>
11+
</field>
12+
</field>
13+
</record>
14+
</data>
15+
</openerp>

0 commit comments

Comments
 (0)