Merge lp:~camptocamp/openobject-addons/trunk-addons-account-reversal into lp:openobject-addons

Proposed by Guewen Baconnier @ Camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/openobject-addons/trunk-addons-account-reversal
Merge into: lp:openobject-addons
Diff against target: 254 lines (+212/-0)
5 files modified
account/__openerp__.py (+1/-0)
account/account.py (+79/-0)
account/wizard/__init__.py (+1/-0)
account/wizard/account_move_reverse.py (+85/-0)
account/wizard/account_move_reverse_view.xml (+46/-0)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/trunk-addons-account-reversal
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp (community) Needs Resubmitting
Fabien (Open ERP) Disapprove
Review via email: mp+75563@code.launchpad.net

Description of the change

Hello,

This is the integration of a reversal function in the account module.

A flag is added on the account moves to know that they have to be reversed or are reversed.
A button in the search view let filter them.

To reverse entries, there is a wizard on the account moves which act on the selected moves.
Thanks to consider this merge proposal.

Best Regards
Guewen

To post a comment you must log in.
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

Being able to reverse an account_move is interesting (rather than the account_reverse module). But we should not have:
  to_be_reversed
  reverse_id

I reject for these reasons, please resubmit when cleaned.

review: Disapprove
Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

Fabien,

I do not get the reason ? is it because we simply add new fields ? What is not clean?

Thanks

Frederic

Revision history for this message
Luc Maurer @ Camptocamp (lmaurer-c2c) wrote :

Sorry Fabien, but these field are really important => perhaps we should
discuss this tooo.

Regards
*
Luc Maurer*
Directeur et associé

*Camptocamp SA*
PSE A
1015 Lausanne
Suisse

Mobile : +41 79 606 07 73
Direct : +41 21 619 10 12

*Camptocamp France SAS*
48 avenue du Lac du Bourget
73372 Le Bourget du Lac
France

Mobile : +41 79 606 07 73
Direct : +33 479 44 44 95
www.camptocamp.com

On Tue, Nov 8, 2011 at 12:16, Frederic Clementi - Camptocamp.com <
<email address hidden>> wrote:

> Fabien,
>
> I do not get the reason ? is it because we simply add new fields ? What is
> not clean?
>
> Thanks
>
> Frederic
>
>
> --
>
> https://code.launchpad.net/~c2c/openobject-addons/trunk-addons-account-reversal/+merge/75563<https://code.launchpad.net/%7Ec2c/openobject-addons/trunk-addons-account-reversal/+merge/75563>
> Your team Camptocamp is subscribed to branch
> lp:~c2c/openobject-addons/trunk-addons-account-reversal.
>

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hello,

I removed the fields, can you check again please ?

This features (how to know which moves have to be reversed, and the link between a move and its reversal) will be done in a module : lp:~c2c/c2c-addons/account_reversal_improvement)

Thanks

review: Needs Resubmitting
Revision history for this message
qdp (OpenERP) (qdp) wrote :

Hello all,

if you have finished your modifications and are ready for another review, please change the status of the merge proposal back to 'needs review' instead of 'work in progress' (as your 'resubmit' review comment is not enough to make the merge proposal appears again in our TODO list).

That's said, i don't have time to review it myself right now ;-), so let me just adjust the status properly.

Thanks,
Quentin

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hello Quentin,

Thanks for your guidance and adjustement of the status. I wasn't aware of that and didn't realize.

Guewen

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hello,

I've done the requested modifications, so why didn't have any news since then ?

Thanks
Guewen

Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

Any news on this please?

Thanks

Frederic

Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

Any news on this please?

Thanks

Frederic

Revision history for this message
James Jesudason (jamesj) wrote :

This module is very useful to us, we use it for:
 * End of period FX revaluations and beginning of new period reversals
 * End of period accruals and beginning of new period reversals

Actually the to_be_reversed and reverse_id makes perfect sense to me and we've found it useful for viewing the reversed journals. OpenERP is missing this functionality and it would be great to get this into the core product.

Thanks

James

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Hello.
@Fabien

Why we must lost the trace from the account move that generate the reversal?.

At least we must have a comment or something to say, @This move is due to reverse this other one@

I am not agreed about have not the fields, as it was originally (at least you say technically it can bring some problem i cant see ) was fine.

Thanks.

Conceptually, i approve, i will test

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Hello Guewen.

Some technical comments that i think needs improvements.

In line 38 of your diff:

+ period_ctx['company_id'] = move.company_id.id

I think you must reset the company_in "only" if company_id is empty.
I mean:

+ period_ctx['company_id'] = not period_ctx.get('comapny_id') and move.company_id.id or period_ctx.get('comapny_id')

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

+ period_ctx['company_id'] = not period_ctx.get('comapany_id') and move.company_id.id or period_ctx.get('comapany_id')

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Sorry for typo mistakes, it should left correct or delete message.

The good one.

+ period_ctx['company_id'] = not period_ctx.get('company_id') and move.company_id.id or period_ctx.get('company_id')

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Other One.

In lines 182:

+ move_ids = context['active_ids']

If you use this method from other context this will fail, we avoid as a good proctice iter a dic with Square brackets, we can change:

+ move_ids = context.get('active_ids', False)
+ if not move_ids:
+ raise Controlled message!

The GTK client in some situations doesn't send this key and it fail ugly ;-)

It is happening here too!

187 + cr, uid,
188 + move_ids,
189 + form['date'],
190 + reversal_period_id=period_id,
191 + reversal_journal_id=journal_id,
192 + move_prefix=form['move_prefix'],
193 + move_line_prefix=form['move_line_prefix'],
194 + context=context)

Thanks....

For me it is approved already, im just helping to improve in a technical better way, to avoid unespected Exceptions.

Unmerged revisions

5001. By Guewen Baconnier @ Camptocamp <email address hidden>

[FIX] According to Fabien's request, removed the reversal_id and to_be_reverse fields. But splitted also the create reversal method to allow us to add these fields in a module.

5000. By Guewen Baconnier @ Camptocamp <email address hidden>

[MRG] from upstream

4999. By Guewen Baconnier @ Camptocamp <email address hidden>

[IMP] account : account.period method find, add company_id filter (from Quentin's Voucher Branch)

4998. By Guewen Baconnier @ Camptocamp <email address hidden>

[MRG] from trunk

4997. By Guewen Baconnier @ Camptocamp <email address hidden>

[MRG] merge from trunk addons

4996. By Guewen Baconnier @ Camptocamp <email address hidden>

[FIX] removed hooks

4995. By Guewen Baconnier @ Camptocamp <email address hidden>

[ADD] account: reversal feature

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account/__openerp__.py'
--- account/__openerp__.py 2011-11-23 14:16:16 +0000
+++ account/__openerp__.py 2011-11-24 15:19:29 +0000
@@ -98,6 +98,7 @@
98 'wizard/account_reconcile_view.xml',98 'wizard/account_reconcile_view.xml',
99 'wizard/account_reconcile_partner_process_view.xml',99 'wizard/account_reconcile_partner_process_view.xml',
100 'wizard/account_automatic_reconcile_view.xml',100 'wizard/account_automatic_reconcile_view.xml',
101 'wizard/account_move_reverse_view.xml',
101 'wizard/account_financial_report_view.xml',102 'wizard/account_financial_report_view.xml',
102 'project/wizard/project_account_analytic_line_view.xml',103 'project/wizard/project_account_analytic_line_view.xml',
103 'account_end_fy.xml',104 'account_end_fy.xml',
104105
=== modified file 'account/account.py'
--- account/account.py 2011-11-23 14:16:16 +0000
+++ account/account.py 2011-11-24 15:19:29 +0000
@@ -1582,6 +1582,85 @@
1582 valid_moves = [move.id for move in valid_moves]1582 valid_moves = [move.id for move in valid_moves]
1583 return len(valid_moves) > 0 and valid_moves or False1583 return len(valid_moves) > 0 and valid_moves or False
15841584
1585 def _move_reversal(self, cr, uid, move, reversal_date, reversal_period_id=False, reversal_journal_id=False,
1586 move_prefix=False, move_line_prefix=False, context=None):
1587 """
1588 Create the reversal of a move
1589
1590 @param move: browse instance of the move to reverse
1591 @param reversal_date: when the reversal must be input
1592 @param reversal_period_id: facultative period to write on the move (use the period of the date if empty
1593 @param reversal_journal_id: facultative journal in which create the move
1594 @param move_prefix: prefix for the move's name
1595 @param move_line_prefix: prefix for the move line's names
1596
1597 @return: Returns the id of the created reversal move
1598 """
1599 if context is None: context = {}
1600 move_line_obj = self.pool.get('account.move.line')
1601 period_obj = self.pool.get('account.period')
1602 period_ctx = context.copy()
1603 period_ctx['company_id'] = move.company_id.id
1604 if not reversal_period_id:
1605 reversal_period_id = period_obj.find(cr, uid, reversal_date, context=period_ctx)[0]
1606
1607 if not reversal_journal_id:
1608 reversal_journal_id = move.journal_id.id
1609 reversal_ctx = context.copy()
1610 reversal_ctx['reversal'] = True
1611 reversal_ref = ''.join([x for x in [move_prefix, move.ref] if x])
1612 reversal_move_id = self.copy(cr, uid, move.id,
1613 default={
1614 'date': reversal_date,
1615 'period_id': reversal_period_id,
1616 'ref': reversal_ref,
1617 'journal_id': reversal_journal_id,
1618 },
1619 context=reversal_ctx)
1620
1621 reversal_move = self.browse(cr, uid, reversal_move_id, context=context)
1622 for reversal_move_line in reversal_move.line_id:
1623 reversal_ml_name = ' '.join([x for x in [move_line_prefix, reversal_move_line.name] if x])
1624 move_line_obj.write(cr, uid, [reversal_move_line.id],
1625 {
1626 'debit': reversal_move_line.credit,
1627 'credit': reversal_move_line.debit,
1628 'amount_currency': reversal_move_line.amount_currency * -1,
1629 'name': reversal_ml_name,
1630 },
1631 context=reversal_ctx,
1632 check=True, update_check=True
1633 )
1634
1635 self.validate(cr, uid, [reversal_move_id], context=reversal_ctx)
1636 return reversal_move_id
1637
1638 def create_reversals(self, cr, uid, ids, reversal_date, reversal_period_id=False, reversal_journal_id=False,
1639 move_prefix=False, move_line_prefix=False, context=None):
1640 """
1641 Create the reversal of one or multiple moves
1642
1643 @param reversal_date: when the reversal must be input
1644 @param reversal_period_id: facultative period to write on the move (use the period of the date if empty
1645 @param reversal_journal_id: facultative journal in which create the move
1646 @param move_prefix: prefix for the move's name
1647 @param move_line_prefix: prefix for the move line's names
1648
1649 @return: Returns a list of ids of the created reversal moves
1650 """
1651 if isinstance(ids, (int, long)):
1652 ids = [ids]
1653
1654 reversed_move_ids = []
1655 for src_move in self.browse(cr, uid, ids, context=context):
1656 reversal_move_id = self._move_reversal(cr, uid, src_move, reversal_date, reversal_period_id=reversal_period_id,
1657 reversal_journal_id=reversal_journal_id, move_prefix=move_prefix,
1658 move_line_prefix=move_line_prefix, context=context)
1659 if reversal_move_id:
1660 reversed_move_ids.append(reversal_move_id)
1661
1662 return reversed_move_ids
1663
1585account_move()1664account_move()
15861665
1587class account_move_reconcile(osv.osv):1666class account_move_reconcile(osv.osv):
15881667
=== modified file 'account/wizard/__init__.py'
--- account/wizard/__init__.py 2011-09-29 11:08:56 +0000
+++ account/wizard/__init__.py 2011-11-24 15:19:29 +0000
@@ -43,6 +43,7 @@
43import account_fiscalyear_close_state43import account_fiscalyear_close_state
44import account_vat44import account_vat
45import account_open_closed_fiscalyear45import account_open_closed_fiscalyear
46import account_move_reverse
4647
47import account_invoice_state48import account_invoice_state
48import account_chart49import account_chart
4950
=== added file 'account/wizard/account_move_reverse.py'
--- account/wizard/account_move_reverse.py 1970-01-01 00:00:00 +0000
+++ account/wizard/account_move_reverse.py 2011-11-24 15:19:29 +0000
@@ -0,0 +1,85 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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
22from osv import osv, fields
23from tools.translate import _
24
25
26class account_move_reversal(osv.osv_memory):
27 _name = "account.move.reverse"
28 _description = "Create reversal of account moves"
29
30 _columns = {
31 'date': fields.date('Reversal Date', required=True, help="Enter the date of the reversal account entries. By default, OpenERP proposes the first day of the next period."),
32 'period_id': fields.many2one('account.period', 'Reversal Period', help="If empty, take the period of the date."),
33 'journal_id': fields.many2one('account.journal', 'Reversal Journal', help='If empty, uses the journal of the journal entry to be reversed.'),
34 'move_prefix': fields.char('Entries Ref. Prefix', size=32, help="Prefix that will be added to the 'Ref' of the journal entry to be reversed to create the 'Ref' of the reversal journal entry (no space added after the prefix)."),
35 'move_line_prefix': fields.char('Items Name Prefix', size=32, help="Prefix that will be added to the name of the journal item to be reversed to create the name of the reversal journal item (a space is added after the prefix)."),
36 }
37
38 def _next_period_first_date(self, cr, uid, context=None):
39 if context is None:
40 context = {}
41 period_obj = self.pool.get('account.period')
42 current_period_id = period_obj.find(cr, uid, context=context)[0]
43 current_period = period_obj.browse(cr, uid, current_period_id, context=context)
44 next_period_id = period_obj.next(cr, uid, current_period, 1, context=context)
45 next_period = period_obj.browse(cr, uid, next_period_id, context=context)
46 return next_period.date_start
47
48 _defaults = {
49 'date': _next_period_first_date,
50 'move_line_prefix': lambda *a: 'REV -',
51 }
52
53 def action_reverse(self, cr, uid, ids, context=None):
54 if context is None:
55 context = {}
56 form = self.read(cr, uid, ids, context=context)[0]
57
58 action = {'type': 'ir.actions.act_window_close'}
59
60 if context.get('active_ids', False):
61 mod_obj = self.pool.get('ir.model.data')
62 act_obj = self.pool.get('ir.actions.act_window')
63 move_obj = self.pool.get('account.move')
64 move_ids = context['active_ids']
65
66 period_id = form.get('period_id', False) and form['period_id'][0] or False
67 journal_id = form.get('journal_id', False) and form['journal_id'][0] or False
68 reversed_move_ids = move_obj.create_reversals(
69 cr, uid,
70 move_ids,
71 form['date'],
72 reversal_period_id=period_id,
73 reversal_journal_id=journal_id,
74 move_prefix=form['move_prefix'],
75 move_line_prefix=form['move_line_prefix'],
76 context=context)
77
78 action_ref = mod_obj.get_object_reference(cr, uid, 'account', 'action_move_journal_line')
79 action_id = action_ref and action_ref[1] or False
80 action = act_obj.read(cr, uid, [action_id], context=context)[0]
81 action['domain'] = str([('id', 'in', reversed_move_ids)])
82 action['name'] = _('Reversal Entries')
83 return action
84
85account_move_reversal()
086
=== added file 'account/wizard/account_move_reverse_view.xml'
--- account/wizard/account_move_reverse_view.xml 1970-01-01 00:00:00 +0000
+++ account/wizard/account_move_reverse_view.xml 2011-11-24 15:19:29 +0000
@@ -0,0 +1,46 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="view_account_move_reverse" model="ir.ui.view">
6 <field name="name">account.move.reverse.form</field>
7 <field name="model">account.move.reverse</field>
8 <field name="type">form</field>
9 <field name="arch" type="xml">
10 <form string="Create reversal journal entries">
11 <field name="date"/>
12 <field name="period_id"/>
13 <field name="journal_id"/>
14 <newline/>
15 <field name="move_prefix" />
16 <field name="move_line_prefix" />
17
18 <separator string="" colspan="4" />
19 <group colspan="4" col="6">
20 <button icon="gtk-cancel" special="cancel" string="Cancel"/>
21 <button icon="gtk-ok" string="Reverse Entries" name="action_reverse" type="object"/>
22 </group>
23 </form>
24 </field>
25 </record>
26
27 <record id="act_account_move_reverse" model="ir.actions.act_window">
28 <field name="name">Reverse Entries</field>
29 <field name="res_model">account.move.reverse</field>
30 <field name="view_type">form</field>
31 <field name="view_mode">form</field>
32 <field name="view_id" ref="view_account_move_reverse"/>
33 <field name="target">new</field>
34 <field name="help">This will create reversal for all selected entries whether checked "to be reversed" or not.</field>
35 </record>
36
37 <record id="ir_account_move_reverse" model="ir.values">
38 <field name="name">Reverse Entries</field>
39 <field name="key2">client_action_multi</field>
40 <field name="model">account.move</field>
41 <field name="value" eval="'ir.actions.act_window,%d'%act_account_move_reverse" />
42 <field name="object" eval="True" />
43 </record>
44
45 </data>
46</openerp>

Subscribers

People subscribed via source and target branches

to all changes: