Skip to content

Commit 45f5849

Browse files
committed
[IMP] - Add a new field into journals to allows merging centralized debit and credit lines in move creation from payment
[IMP] - Add an action to delete move from the payment order [IMP] - Improve the generation of the move generation
1 parent 13f1d8c commit 45f5849

File tree

6 files changed

+150
-14
lines changed

6 files changed

+150
-14
lines changed

account_payment_account_move/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#
2020
###############################################################################
2121

22+
from . import account_journal
2223
from . import payment_order
2324

2425
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

account_payment_account_move/__openerp__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
],
3434
"demo":[],
3535
"data": [
36+
"account_journal_view.xml",
3637
"payment_export_view.xml",
3738
],
3839
"description": """
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
###############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# Copyright (C) 2015-Today Julius Network Solutions SARL <[email protected]>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (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 General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
###############################################################################
21+
22+
from openerp import models, fields
23+
24+
class account_journal(models.Model):
25+
_inherit = 'account.journal'
26+
27+
group_payment_line = fields.\
28+
Boolean('Group payment lines', default=True,
29+
help='If checked, the system will group lines in the move' \
30+
'generated from the payment')
31+
32+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<openerp>
3+
<data>
4+
5+
<record id="view_account_journal_group_payment_line_form" model="ir.ui.view">
6+
<field name="name">account.journal.group.payment.line.form</field>
7+
<field name="model">account.journal</field>
8+
<field name="inherit_id" ref="account.view_account_journal_form"/>
9+
<field name="arch" type="xml">
10+
<field name="centralisation" position="after">
11+
<field name="group_payment_line"/>
12+
</field>
13+
</field>
14+
</record>
15+
16+
</data>
17+
</openerp>

account_payment_account_move/payment_export_view.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
<field name="move_id"/>
1313
</field>
1414
<button name="cancel" position="after">
15-
<button name="create_account_move" string="Create move" type="object"/>
15+
<button name="create_account_move" string="Create move" type="object"
16+
attrs="{'invisible': [('move_id', '!=', False)]}"/>
17+
<button name="delete_account_move" string="Delete move" type="object"
18+
attrs="{'invisible': [('move_id', '=', False)]}"/>
1619
</button>
1720
</field>
1821
</record>

account_payment_account_move/payment_order.py

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#
2020
###############################################################################
2121

22-
from openerp import models, fields, api
22+
from openerp import models, fields, api, _
23+
from openerp.exceptions import Warning
2324

2425
class payment_order(models.Model):
2526
_inherit = 'payment.order'
@@ -29,9 +30,17 @@ class payment_order(models.Model):
2930

3031
@api.one
3132
def create_account_move(self):
33+
"""
34+
This method is creating an account move from the payment.
35+
"""
36+
if not self.journal_id:
37+
raise Warning(_('Impossible to create the move,'\
38+
'\nPlease select a journal.'))
39+
if self.move_id:
40+
raise Warning(_("There's already a move related to this payment."))
3241
move_obj = self.env['account.move']
3342
move_line_obj = self.env['account.move.line']
34-
if not self.move_id:
43+
if not self.move_id and self.line_ids:
3544
today = fields.Date.today()
3645
move = move_obj.create({
3746
'journal_id': self.journal_id.id,
@@ -41,36 +50,109 @@ def create_account_move(self):
4150
})
4251
self.move_id = move.id
4352
reconciles = []
53+
group_lines = self.journal_id.group_payment_line
54+
debit_grouped = 0.0
55+
credit_grouped = 0.0
56+
credit_account_id = self.journal_id.default_credit_account_id.id
57+
debit_account_id = self.journal_id.default_debit_account_id.id
4458
for line in self.line_ids:
4559
move_line = line.move_line_id
46-
debit_line = move_line_obj.\
60+
if not move_line:
61+
raise Warning(_('The line %s has not related move' %line.name))
62+
debit = move_line.debit
63+
credit = move_line.credit
64+
account_id = move_line.account_id.id
65+
if not account_id:
66+
if debit:
67+
account_id = credit_account_id
68+
else:
69+
account_id = debit_account_id
70+
if not account_id:
71+
raise Warning(_("There is at least one line without an " \
72+
"account defined, so make sure the defaults " \
73+
"credit and debit account are defined in " \
74+
"the related Journal."))
75+
to_reconcile_line = move_line_obj.\
4776
create({
4877
'partner_id': move_line.partner_id.id,
4978
'name': move_line.name,
5079
'journal_id': self.journal_id.id,
5180
'date': self.move_id.date,
52-
'debit': move_line.credit,
53-
'credit': 0,
54-
'account_id': move_line.account_id.id,
81+
'debit': credit,
82+
'credit': debit,
83+
'account_id': account_id,
5584
'period_id': self.move_id.period_id.id,
5685
'move_id': self.move_id.id,
5786
})
58-
credit_line = move_line_obj.\
87+
if not group_lines:
88+
other_line = move_line_obj.\
89+
create({
90+
'partner_id': move_line.partner_id.id,
91+
'name': move_line.name,
92+
'journal_id': self.journal_id.id,
93+
'date': self.move_id.date,
94+
'debit': debit,
95+
'credit': credit,
96+
'account_id': debit and credit_account_id or \
97+
debit_account_id,
98+
'period_id': self.move_id.period_id.id,
99+
'move_id': self.move_id.id,
100+
})
101+
else:
102+
credit_grouped += credit
103+
debit_grouped += debit
104+
reconciles.append(move_line + to_reconcile_line)
105+
if credit_grouped:
106+
move_line_obj.\
59107
create({
60-
'partner_id': move_line.partner_id.id,
61-
'name': move_line.name,
108+
'partner_id': False,
109+
'name': _('Centralized credit'),
62110
'journal_id': self.journal_id.id,
63111
'date': self.move_id.date,
64112
'debit': 0,
65-
'credit': move_line.credit,
66-
'account_id': self.journal_id.\
67-
default_debit_account_id.id,
113+
'credit': credit_grouped,
114+
'account_id': debit_account_id,
115+
'period_id': self.move_id.period_id.id,
116+
'move_id': self.move_id.id,
117+
})
118+
if debit_grouped:
119+
move_line_obj.\
120+
create({
121+
'partner_id': False,
122+
'name': _('Centralized debit'),
123+
'journal_id': self.journal_id.id,
124+
'date': self.move_id.date,
125+
'debit': debit_grouped,
126+
'credit': 0,
127+
'account_id': credit_account_id,
68128
'period_id': self.move_id.period_id.id,
69129
'move_id': self.move_id.id,
70130
})
71-
reconciles.append(move_line + debit_line)
72131
for rec in reconciles:
73132
rec.reconcile('manual')
74133
return True
75134

135+
@api.one
136+
def delete_account_move(self):
137+
if not self.move_id:
138+
raise Warning(_("There's nothing to delete"))
139+
if self.move_id.state != 'draft':
140+
raise Warning(_("Impossible to delete this move, " \
141+
"please set it to draft before deleting it"))
142+
line_obj = self.env['account.move.line']
143+
lines = line_obj.search(['|',
144+
('reconcile_partial_id', '!=', False),
145+
('reconcile_id', '!=', False),
146+
('move_id', '=', self.move_id.id),
147+
])
148+
reconciles = self.env['account.move.reconcile']
149+
for line in lines:
150+
if line.reconcile_id:
151+
reconciles |= line.reconcile_id
152+
if line.reconcile_partial_id:
153+
reconciles |= line.reconcile_partial_id
154+
reconciles.unlink()
155+
self.move_id.unlink()
156+
return True
157+
76158
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 commit comments

Comments
 (0)