Merge lp:~camptocamp/account-consolidation/account-consolidation-fix-mono-currency into lp:~account-core-editors/account-consolidation/7.0

Proposed by Nicolas Bessi - Camptocamp
Status: Merged
Merged at revision: 17
Proposed branch: lp:~camptocamp/account-consolidation/account-consolidation-fix-mono-currency
Merge into: lp:~account-core-editors/account-consolidation/7.0
Diff against target: 722 lines (+333/-129)
13 files modified
account_consolidation/__init__.py (+4/-3)
account_consolidation/__openerp__.py (+37/-38)
account_consolidation/account.py (+10/-7)
account_consolidation/account_move_line.py (+51/-0)
account_consolidation/account_move_line_view.xml (+30/-0)
account_consolidation/account_view.xml (+4/-3)
account_consolidation/analysis_view.xml (+39/-0)
account_consolidation/company.py (+14/-6)
account_consolidation/company_view.xml (+2/-1)
account_consolidation/consolidation_menu.xml (+3/-0)
account_consolidation/data.xml (+13/-0)
account_consolidation/wizard/consolidation_base.py (+11/-8)
account_consolidation/wizard/consolidation_consolidate.py (+115/-63)
To merge this branch: bzr merge lp:~camptocamp/account-consolidation/account-consolidation-fix-mono-currency
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Guewen Baconnier @ Camptocamp Needs Fixing
Review via email: mp+151966@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Typo lines 36,37:
s/currency_vale/currency_value/

Apart that, the fix seems correct to me.

review: Needs Fixing
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Forget to merge a revision, here it is.

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Frédéric has detected some side effect to be fixed

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Add some fixes in lines generation.

Implement the hook to allows to manage consolidation difference.

Add some usability improvements:
-defaults value
-label improvement
-filtered view in move line
-missing tooltip

Add the possibility to group by subsidaries

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

> Add some fixes in lines generation.
>
> Implement the hook to allows to manage consolidation difference.
>
> Add some usability improvements:
> -defaults value
> -label improvement
> -filtered view in move line
> -missing tooltip
>
> Add the possibility to group by subsidaries

So what is the status of the MP? is it work in progress or can we review now?

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

It can be reviewed the status is not anymore "work in progress".

Regards

Nicolas

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Can a renaming of consol_company_id be considered?

line 549: "if balance" I thing this could be wrong, because of rounding errors. Are you sure you don't need to use the rounding methods available in the framework, or float_is_zero + a precision here?

line 603: you can't return None in a "public" method which can be called from xmlrpc. Either return False, or rename the method.

review: Needs Fixing (code review, no test)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Thanks for the review.

For the consol_company_id I agree with you it should be subsidary_id but I do not want to alter data model.

For the rounding your right. There is no mean to create consolidation line for difference < than 0.01. I will extend the test.

34. By Nicolas Bessi - Camptocamp

[FIX] None return in public function + conso. differences smaller than cent will not be generated

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Add recommended fixes

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

0.01 does not represent the same amount according to the currency.
That's why the model res.currency has a method `is_zero`. This method uses `openerp.tools.float_is_zero` but uses the configuration of the currency for the precision.
Is it applicable here?

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

The goal of this function is to create the move line to manage rounding difference, transitory difference but when it is call the currency conversion has been done upstream and the move we want to adjust is already in "holding" currency.

But you remark is pertinent in the consolidate account method and I will keep it in mind when we will implement the support of auxiliay accounts split.

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

> The goal of this function is to create the move line to manage rounding
> difference, transitory difference but when it is call the currency conversion
> has been done upstream and the move we want to adjust is already in "holding"
> currency.

I don't speak about currency conversion.

You have to use `is_zero` on the holding's currency instead of `openerp.tools.float_is_zero`.

Here is the method I speak about:

    def is_zero(self, cr, uid, currency, amount):
        """Returns true if ``amount`` is small enough to be treated as
           zero according to ``currency``'s rounding rules.

           Warning: ``is_zero(amount1-amount2)`` is not always equivalent to
           ``compare_amounts(amount1,amount2) == 0``, as the former will round after
           computing the difference, while the latter will round before, giving
           different results for e.g. 0.006 and 0.002 at 2 digits precision.

           :param browse_record currency: currency for which we are rounding
           :param float amount: amount to compare with currency's zero
        """
        return float_is_zero(amount, precision_rounding=currency.rounding)

review: Needs Fixing
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Ok I get your point.
Yep, this seems to be the correct solution.

35. By Nicolas Bessi - Camptocamp

[FIX] Consolidation difference uses currency is_zero instead of float_is_zero
+ small style cleanup in method

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Consolidation difference uses currency is_zero instead of float_is_zero
+ small style cleanup in method

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) :
review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_consolidation/__init__.py'
--- account_consolidation/__init__.py 2011-08-12 15:39:07 +0000
+++ account_consolidation/__init__.py 2013-03-21 10:33:20 +0000
@@ -1,3 +1,4 @@
1import company1from . import company
2import account2from . import account
3import wizard3from . import account_move_line
4from . import wizard
45
=== modified file 'account_consolidation/__openerp__.py'
--- account_consolidation/__openerp__.py 2013-01-04 13:09:21 +0000
+++ account_consolidation/__openerp__.py 2013-03-21 10:33:20 +0000
@@ -18,15 +18,12 @@
18# along with this program. If not, see <http://www.gnu.org/licenses/>.18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#19#
20##############################################################################20##############################################################################
2121{"name": "Account Consolidation",
22{22 "version": "1.0",
23 "name" : "Account Consolidation",23 "author": "Camptocamp",
24 "version" : "1.0",24 "license": "AGPL-3",
25 "author" : "Camptocamp",25 "category": "Generic Modules/Accounting",
26 'license': 'AGPL-3',26 "description": """
27 "category" : "Generic Modules/Accounting",
28 "description":
29"""
30Account consolidation27Account consolidation
31=====================28=====================
3229
@@ -42,32 +39,34 @@
42it can be found on the account-financial-tools_39it can be found on the account-financial-tools_
43project40project
4441
45.. _account-financial-tools: https://launchpad.net/account-financial-tools42.. _account-financial-tools: https://launchpad.net/account-financial-tools""",
4643
47""",44 "website": "http://www.camptocamp.com",
48 "website": "http://www.camptocamp.com",45 "depends": ['base',
49 "depends" : [46 'account',
50 'base',47 'account_reversal', # TODO check account_constraints compat.
51 'account',48 ],
52 'account_reversal',49
53 ],50 "demo_xml": ['demo/consolidation_demo.xml',
54 "demo_xml" : [51 'demo/chart_a_demo.xml',
55 'demo/consolidation_demo.xml',52 'demo/chart_b_demo.xml',
56 'demo/chart_a_demo.xml',53 ],
57 'demo/chart_b_demo.xml',54
58 ],55 "data": ['data.xml',
59 "data" : [56 'account_move_line_view.xml',
60 'company_view.xml',57 'company_view.xml',
61 'account_view.xml',58 'account_view.xml',
62 'wizard/consolidation_check_view.xml',59 'wizard/consolidation_check_view.xml',
63 'wizard/consolidation_consolidate_view.xml',60 'wizard/consolidation_consolidate_view.xml',
64 'consolidation_menu.xml',61 'consolidation_menu.xml',
65 ],62 'analysis_view.xml'
66 'test': [63 ],
67 'test/test_data.yml',64
68 'test/consolidation_checks.yml',65 "test": ['test/test_data.yml',
69 'test/consolidation_consolidate.yml',66 'test/consolidation_checks.yml',
70 ],67 'test/consolidation_consolidate.yml',
71 "active": False,68 ],
72 "installable": True,69
73}70 "active": False,
71 "installable": True,
72 }
7473
=== modified file 'account_consolidation/account.py'
--- account_consolidation/account.py 2013-01-04 14:34:13 +0000
+++ account_consolidation/account.py 2013-03-21 10:33:20 +0000
@@ -32,10 +32,12 @@
32 help="Currency rate type used on this account "32 help="Currency rate type used on this account "
33 "for the consolidation. "33 "for the consolidation. "
34 "Leave empty to use the rate type of the account type."),34 "Leave empty to use the rate type of the account type."),
35
35 'consolidation_mode': fields.selection(36 'consolidation_mode': fields.selection(
36 [('ytd', 'YTD'),37 [('ytd', 'YTD'),
37 ('period', 'Period Movements')],38 ('period', 'Period Movements')],
38 'Consolidation Mode'),39 'Consolidation Mode',
40 help="This must be set on the holding company accounts only"),
39 }41 }
4042
4143
@@ -49,15 +51,16 @@
49 help="Currency rate type used on this account type "51 help="Currency rate type used on this account type "
50 "for the consolidation. "52 "for the consolidation. "
51 "Leave empty to use the 'spot' rate type."),53 "Leave empty to use the 'spot' rate type."),
54
52 'consolidation_mode': fields.selection(55 'consolidation_mode': fields.selection(
53 [('ytd', 'YTD'),56 [('ytd', 'YTD'),
54 ('period', 'Period Movements')],57 ('period', 'Period Movements')],
55 'Consolidation Mode'),58 'Consolidation Mode',
56 }59 help="This must be set on the holding company accounts only"),
5760
58 _defaults = {61 }
59 'consolidation_mode': 'ytd',62
60 }63 _defaults = {'consolidation_mode': 'ytd'}
6164
6265
63class account_move(orm.Model):66class account_move(orm.Model):
6467
=== added file 'account_consolidation/account_move_line.py'
--- account_consolidation/account_move_line.py 1970-01-01 00:00:00 +0000
+++ account_consolidation/account_move_line.py 2013-03-21 10:33:20 +0000
@@ -0,0 +1,51 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Nicolas Bessi Guewen Baconnier
5# Copyright 2011-2013 Camptocamp SA
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 openerp.osv import orm, fields
23
24
25class AccountMoveLine(orm.Model):
26 _inherit = 'account.move.line'
27
28 def _current_company(self, cursor, uid, ids, name, args, context=None):
29 company_id = self.pool['res.company']._company_default_get(cursor, uid)
30 curr_ids = self.search(cursor, uid, [('company_id', '=', company_id)])
31 res = dict([(tid, tid in curr_ids) for tid in ids])
32 return res
33
34
35 def search_is_current_company(self, cursor, uid, obj, name, args, context=None):
36 company_id = self.pool['res.company']._company_default_get(cursor, uid)
37 res = self.search(cursor, uid, [('company_id', '=', company_id)])
38 return [('id', 'in', res)]
39
40 _columns = {'consol_company_id': fields.related('move_id', 'consol_company_id',
41 relation='res.company',
42 type="many2one",
43 string='Subsidaries',
44 store=True, # for the group_by
45 readonly=True),
46
47 'is_current_company': fields.function(_current_company,
48 string="Current company",
49 type="boolean",
50 fnct_search=search_is_current_company)
51 }
052
=== added file 'account_consolidation/account_move_line_view.xml'
--- account_consolidation/account_move_line_view.xml 1970-01-01 00:00:00 +0000
+++ account_consolidation/account_move_line_view.xml 2013-03-21 10:33:20 +0000
@@ -0,0 +1,30 @@
1<openerp>
2 <data>
3 <record id="view_move_line_tree" model="ir.ui.view">
4 <field name="name">account.move.line.tree.conso</field>
5 <field name="model">account.move.line</field>
6 <field name="inherit_id" ref="account.view_move_line_tree"/>
7 <field name="arch" type="xml">
8 <field name="date" position="before">
9 <field name="consol_company_id"
10 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"/>
11 <field name="is_current_company" invisible="1"/>
12 </field>
13 </field>
14 </record>
15
16 <record id="view_account_move_line_filter" model="ir.ui.view">
17 <field name="name">Journal Items conso</field>
18 <field name="model">account.move.line</field>
19 <field name="inherit_id" ref="account.view_account_move_line_filter"/>
20 <field name="arch" type="xml">
21 <filter string="Period" position="after">
22 <filter string="Subsidaries"
23 icon="terp-folder-green"
24 context="{'group_by':'consol_company_id'}"
25 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"/>
26 </filter>
27 </field>
28 </record>
29 </data>
30</openerp>
031
=== modified file 'account_consolidation/account_view.xml'
--- account_consolidation/account_view.xml 2013-01-04 15:03:23 +0000
+++ account_consolidation/account_view.xml 2013-03-21 10:33:20 +0000
@@ -10,7 +10,7 @@
10 <field name="arch" type="xml">10 <field name="arch" type="xml">
11 <data>11 <data>
12 <xpath expr="//field[@name='note']" position="after">12 <xpath expr="//field[@name='note']" position="after">
13 <group>13 <group groups="account_consolidation.consolidation_manager">
14 <separator string="Consolidation" colspan="2"/>14 <separator string="Consolidation" colspan="2"/>
15 <field name="consolidation_rate_type_id" widget="selection"/>15 <field name="consolidation_rate_type_id" widget="selection"/>
16 <field name="consolidation_mode"/>16 <field name="consolidation_mode"/>
@@ -28,7 +28,7 @@
28 <field name="type">form</field>28 <field name="type">form</field>
29 <field name="arch" type="xml">29 <field name="arch" type="xml">
30 <separator string="Description" position="before">30 <separator string="Description" position="before">
31 <group col="2" colspan="2">31 <group col="2" colspan="2" groups="account_consolidation.consolidation_manager">
32 <separator string="Consolidation" colspan="4"/>32 <separator string="Consolidation" colspan="4"/>
33 <field name="consolidation_rate_type_id" widget="selection"/>33 <field name="consolidation_rate_type_id" widget="selection"/>
34 <field name="consolidation_mode"/>34 <field name="consolidation_mode"/>
@@ -45,7 +45,8 @@
45 <field name="arch" type="xml">45 <field name="arch" type="xml">
46 <field name="company_id" position="after">46 <field name="company_id" position="after">
47 <field name="consol_company_id"47 <field name="consol_company_id"
48 attrs="{'invisible': [('consol_company_id', '=', False)]}"/>48 attrs="{'invisible': [('consol_company_id', '=', False)]}"
49 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"/>
49 </field>50 </field>
50 </field>51 </field>
51 </record>52 </record>
5253
=== added file 'account_consolidation/analysis_view.xml'
--- account_consolidation/analysis_view.xml 1970-01-01 00:00:00 +0000
+++ account_consolidation/analysis_view.xml 2013-03-21 10:33:20 +0000
@@ -0,0 +1,39 @@
1<openerp>
2 <data>
3
4 <menuitem id="menu_conso_entries"
5 name="Consolidation Entries"
6 parent="account.menu_finance"
7 sequence="5"
8 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"/>
9
10 <record id="action_account_moves_all_a" model="ir.actions.act_window">
11 <field name="context">{'journal_type':'general'}</field>
12 <field name="name">Journal Items</field>
13 <field name="domain">[('is_current_company', '=', True)]</field>
14 <field name="res_model">account.move.line</field>
15 <field name="view_id" ref="account.view_move_line_tree"/>
16 <field name="view_mode">tree_account_move_line_quickadd,form</field>
17 <field name="help" type="html">
18 <p class="oe_view_nocontent_create">
19 Select the period and the journal you want to fill.
20 </p><p>
21 This view can be used by accountants in order to quickly record
22 entries in OpenERP. If you want to record a supplier invoice,
23 start by recording the line of the expense account. OpenERP
24 will propose to you automatically the Tax related to this
25 account and the counterpart "Account Payable".
26 </p>
27 </field>
28 </record>
29
30 <menuitem
31 action="action_account_moves_all_a"
32 icon="STOCK_JUSTIFY_FILL"
33 id="menu_action_account_moves_all"
34 parent="menu_conso_entries"
35 sequence="1"
36 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"/>
37
38 </data>
39</openerp>
040
=== modified file 'account_consolidation/company.py'
--- account_consolidation/company.py 2013-01-04 14:34:13 +0000
+++ account_consolidation/company.py 2013-03-21 10:33:20 +0000
@@ -25,9 +25,17 @@
25class res_company(orm.Model):25class res_company(orm.Model):
26 _inherit = 'res.company'26 _inherit = 'res.company'
2727
28 _columns = {28 _columns = {'consolidation_chart_account_id': fields.many2one(
29 'consolidation_chart_account_id': fields.many2one(29 'account.account',
30 'account.account',30 'Chart of Accounts for Consolidation',
31 'Chart of Accounts for Consolidation',31 domain=[('parent_id', '=', False)],
32 domain=[('parent_id', '=', False)]),32 help=("Current company root account"
33 }33 " to be used when consolidating")),
34
35 'consolidation_diff_account_id': fields.many2one(
36 'account.account',
37 'Consolidation difference account',
38 domain=[('type', '=', 'other')],
39 help=("Conso. differences will be affected"
40 " to this account"))
41 }
3442
=== modified file 'account_consolidation/company_view.xml'
--- account_consolidation/company_view.xml 2011-08-19 07:16:03 +0000
+++ account_consolidation/company_view.xml 2013-03-21 10:33:20 +0000
@@ -9,9 +9,10 @@
9 <field name="type">form</field>9 <field name="type">form</field>
10 <field name="arch" type="xml">10 <field name="arch" type="xml">
11 <page string="Configuration" position="inside">11 <page string="Configuration" position="inside">
12 <group col="2" colspan="2">12 <group col="2" colspan="2" groups="account_consolidation.consolidation_manager">
13 <separator string="Accounts Consolidation" colspan="2"/>13 <separator string="Accounts Consolidation" colspan="2"/>
14 <field name="consolidation_chart_account_id" colspan="2"/>14 <field name="consolidation_chart_account_id" colspan="2"/>
15 <field name="consolidation_diff_account_id" colspan="2"/>
15 </group>16 </group>
16 </page>17 </page>
17 </field>18 </field>
1819
=== modified file 'account_consolidation/consolidation_menu.xml'
--- account_consolidation/consolidation_menu.xml 2011-08-12 15:39:07 +0000
+++ account_consolidation/consolidation_menu.xml 2013-03-21 10:33:20 +0000
@@ -5,18 +5,21 @@
5 <menuitem5 <menuitem
6 name="Consolidation"6 name="Consolidation"
7 parent="account.menu_finance_periodical_processing"7 parent="account.menu_finance_periodical_processing"
8 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"
8 id="menu_consolidation"/>9 id="menu_consolidation"/>
910
10 <menuitem11 <menuitem
11 name="Consolidation: Checks"12 name="Consolidation: Checks"
12 parent="menu_consolidation"13 parent="menu_consolidation"
13 action="action_consolidation_checks"14 action="action_consolidation_checks"
15 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"
14 id="menu_consolidation_checks"/>16 id="menu_consolidation_checks"/>
1517
16 <menuitem18 <menuitem
17 name="Consolidation: Consolidate"19 name="Consolidation: Consolidate"
18 parent="menu_consolidation"20 parent="menu_consolidation"
19 action="action_consolidation_consolidate"21 action="action_consolidation_consolidate"
22 groups="account_consolidation.consolidation_manager,account_consolidation.consolidation_user"
20 id="menu_consolidation_consolidate"/>23 id="menu_consolidation_consolidate"/>
2124
22 </data>25 </data>
2326
=== added file 'account_consolidation/data.xml'
--- account_consolidation/data.xml 1970-01-01 00:00:00 +0000
+++ account_consolidation/data.xml 2013-03-21 10:33:20 +0000
@@ -0,0 +1,13 @@
1<openerp>
2 <data>
3 <record id="consolidation_manager" model="res.groups">
4 <field name="name">Consolidation manager</field>
5 <field name="category_id" ref="base.module_category_accounting_and_finance"/>
6 </record>
7
8 <record id="consolidation_user" model="res.groups">
9 <field name="name">Consolidation user</field>
10 <field name="category_id" ref="base.module_category_accounting_and_finance"/>
11 </record>
12 </data>
13</openerp>
014
=== modified file 'account_consolidation/wizard/consolidation_base.py'
--- account_consolidation/wizard/consolidation_base.py 2013-01-09 09:31:39 +0000
+++ account_consolidation/wizard/consolidation_base.py 2013-03-21 10:33:20 +0000
@@ -28,11 +28,14 @@
28 _description = 'Common consolidation wizard. Intended to be inherited'28 _description = 'Common consolidation wizard. Intended to be inherited'
2929
30 def _default_company(self, cr, uid, context=None):30 def _default_company(self, cr, uid, context=None):
31 user = self.pool.get('res.users').browse(cr, uid, uid, context=context)31 comp_obj = self.pool['res.company']
32 if user.company_id:32 return comp_obj._company_default_get(cr, uid)
33 return user.company_id.id33
34 return self.pool.get('res.company').search(34 def _default_chart(self, cr, uid, context=None):
35 cr, uid, [('parent_id', '=', False)])[0]35 comp_obj = self.pool['res.company']
36 comp_id = comp_obj._company_default_get(cr, uid)
37 company = comp_obj.browse(cr, uid, comp_id)
38 return company.consolidation_chart_account_id.id
3639
37 _columns = {40 _columns = {
38 'fiscalyear_id': fields.many2one(41 'fiscalyear_id': fields.many2one(
@@ -57,9 +60,9 @@
57 required=True)60 required=True)
58 }61 }
5962
60 _defaults = {63 _defaults = {'company_id': _default_company,
61 'company_id': _default_company,64 'holding_chart_account_id': _default_chart,
62 }65 }
6366
64 def on_change_company_id(self, cr, uid, ids, company_id, context=None):67 def on_change_company_id(self, cr, uid, ids, company_id, context=None):
65 """68 """
6669
=== modified file 'account_consolidation/wizard/consolidation_consolidate.py'
--- account_consolidation/wizard/consolidation_consolidate.py 2013-01-09 09:51:45 +0000
+++ account_consolidation/wizard/consolidation_consolidate.py 2013-03-21 10:33:20 +0000
@@ -20,13 +20,22 @@
20##############################################################################20##############################################################################
2121
22from openerp.osv import orm, fields22from openerp.osv import orm, fields
23from openerp.osv.osv import except_osv
23from openerp.tools.translate import _24from openerp.tools.translate import _
2425
25
26class account_consolidation_consolidate(orm.TransientModel):26class account_consolidation_consolidate(orm.TransientModel):
27 _name = 'account.consolidation.consolidate'27 _name = 'account.consolidation.consolidate'
28 _inherit = 'account.consolidation.base'28 _inherit = 'account.consolidation.base'
2929
30 def _default_journal(self, cr, uid, context=None):
31 comp_obj = self.pool['res.company']
32 journ_obj = self.pool['account.journal']
33 comp_id = comp_obj._company_default_get(cr, uid)
34 journal_id = journ_obj.search(cr, uid, [('company_id', '=', comp_id)], limit=1)
35 if journal_id:
36 return journal_id[0]
37 return False
38
30 _columns = {39 _columns = {
31 'from_period_id': fields.many2one(40 'from_period_id': fields.many2one(
32 'account.period',41 'account.period',
@@ -35,19 +44,23 @@
35 help="Select the same period in 'from' and 'to' "44 help="Select the same period in 'from' and 'to' "
36 "if you want to proceed with a single period. "45 "if you want to proceed with a single period. "
37 "Start Period is ignored for Year To Date accounts."),46 "Start Period is ignored for Year To Date accounts."),
47
38 'to_period_id': fields.many2one(48 'to_period_id': fields.many2one(
39 'account.period',49 'account.period',
40 'End Period',50 'End Period',
41 required=True,51 required=True,
42 help="The consolidation will be done at the very "52 help="The consolidation will be done at the very "
43 "last date of the selected period."),53 "last date of the selected period."),
54
44 'journal_id': fields.many2one(55 'journal_id': fields.many2one(
45 'account.journal', 'Journal', required=True),56 'account.journal', 'Journal', required=True),
57
46 'target_move': fields.selection(58 'target_move': fields.selection(
47 [('posted', 'All Posted Entries'),59 [('posted', 'All Posted Entries'),
48 ('all', 'All Entries')],60 ('all', 'All Entries')],
49 'Target Moves',61 'Target Moves',
50 required=True),62 required=True),
63
51 'subsidiary_ids': fields.many2many(64 'subsidiary_ids': fields.many2many(
52 'res.company',65 'res.company',
53 'account_conso_conso_comp_rel',66 'account_conso_conso_comp_rel',
@@ -57,9 +70,9 @@
57 required=True),70 required=True),
58 }71 }
5972
60 _defaults = {73 _defaults = {'target_move': 'posted',
61 'target_move': 'posted'74 'journal_id': _default_journal,
62 }75 }
6376
64 def _check_periods_fy(self, cr, uid, ids, context=None):77 def _check_periods_fy(self, cr, uid, ids, context=None):
65 if isinstance(ids, (int, long)):78 if isinstance(ids, (int, long)):
@@ -88,13 +101,13 @@
88 """101 """
89 result = {}102 result = {}
90 period_obj = self.pool.get('account.period')103 period_obj = self.pool.get('account.period')
91 from_period = period_obj.browse(104 from_period = period_obj.browse(cr, uid, from_period_id,
92 cr, uid, from_period_id, context=context)105 context=context)
93 if not to_period_id:106 if not to_period_id:
94 result['to_period_id'] = from_period_id107 result['to_period_id'] = from_period_id
95 else:108 else:
96 to_period = period_obj.browse(109 to_period = period_obj.browse(cr, uid, to_period_id,
97 cr, uid, to_period_id, context=context)110 context=context)
98 if to_period.date_start < from_period.date_start:111 if to_period.date_start < from_period.date_start:
99 result['to_period_id'] = from_period_id112 result['to_period_id'] = from_period_id
100113
@@ -155,13 +168,46 @@
155 context=context)168 context=context)
156 return subs_period_ids169 return subs_period_ids
157170
158 def create_rate_difference_line(self, cr, uid, ids, move_id, context):171 def create_rate_difference_line(self, cr, uid, ids, move_id, consolidation_mode, context):
159 """172 """
160 Placeholder for creation of a move line173 We can have consolidation difference when a account is in YTD but in normal counterpart
161 for the gain/loss currency difference174 has a different setting.
175 """
176 move_obj = self.pool['account.move']
177 move_line_obj = self.pool['account.move.line']
178 currency_obj = self.pool['res.currency']
179 move = move_obj.browse(cr, uid, move_id, context=context)
162180
163 :param move_id: ID of the move181 if not move.line_id:
164 """182 return False
183 diff_account = move.company_id.consolidation_diff_account_id
184 if not diff_account:
185 raise except_osv(_('Settings ERROR'),
186 _('Please set the "Consolidation difference account"'
187 ' in company %s') % move.company_id.name)
188 debit = credit = 0.0
189 for line in move.line_id:
190 debit += line.debit
191 credit += line.credit
192 balance = debit - credit
193 # We do not want to create counter parts for amount smaller than
194 # "holding" company currency rounding policy.
195 # As generated lines are in draft state, accountant will be able to manage
196 # special cases
197 move_is_balanced = currency_obj.is_zero(cr, uid, move.company_id.currency_id, balance)
198 if not move_is_balanced:
199 diff_vals = {'account_id': diff_account.id,
200 'move_id': move.id,
201 'journal_id': move.journal_id.id,
202 'period_id': move.period_id.id,
203 'company_id': move.company_id.id,
204 'date': move.date,
205 'debit': abs(balance) if balance < 0.0 else 0.0,
206 'credit': balance if balance > 0.0 else 0.0,
207 'name': _('Consolidation difference in mode %s') % consolidation_mode
208 }
209 return move_line_obj.create(cr, uid, diff_vals, context=context)
210 return False
165211
166 def consolidate_account(self, cr, uid, ids, consolidation_mode,212 def consolidate_account(self, cr, uid, ids, consolidation_mode,
167 subsidiary_period_ids, state, move_id,213 subsidiary_period_ids, state, move_id,
@@ -193,14 +239,13 @@
193 currency_obj = self.pool.get('res.currency')239 currency_obj = self.pool.get('res.currency')
194240
195 move = move_obj.browse(cr, uid, move_id, context=context)241 move = move_obj.browse(cr, uid, move_id, context=context)
196 holding_account = account_obj.browse(242 holding_account = account_obj.browse(cr, uid, holding_account_id,
197 cr, uid, holding_account_id, context=context)243 context=context)
198244
199 subsidiary_account_id = account_obj.search(245 subsidiary_account_id = account_obj.search(cr, uid,
200 cr, uid,246 [('code', '=', holding_account.code),
201 [('code', '=', holding_account.code),247 ('company_id', '=', subsidiary_id)],
202 ('company_id', '=', subsidiary_id)],248 context=context)
203 context=context)
204249
205 if not subsidiary_account_id:250 if not subsidiary_account_id:
206 # an account may exist on the holding and not in the subsidiaries,251 # an account may exist on the holding and not in the subsidiaries,
@@ -209,8 +254,8 @@
209254
210 browse_ctx = dict(context, state=state, periods=subsidiary_period_ids)255 browse_ctx = dict(context, state=state, periods=subsidiary_period_ids)
211 # 1st item because the account's code is unique per company256 # 1st item because the account's code is unique per company
212 subs_account = account_obj.browse(257 subs_account = account_obj.browse(cr, uid, subsidiary_account_id[0],
213 cr, uid, subsidiary_account_id[0], context=browse_ctx)258 context=browse_ctx)
214259
215 vals = {260 vals = {
216 'name': _("Consolidation line in %s mode") % consolidation_mode,261 'name': _("Consolidation line in %s mode") % consolidation_mode,
@@ -222,34 +267,34 @@
222 'date': move.date267 'date': move.date
223 }268 }
224269
270 balance = subs_account.balance
271 if not balance:
272 return False
225 if (holding_account.company_currency_id.id ==273 if (holding_account.company_currency_id.id ==
226 subs_account.company_currency_id.id):274 subs_account.company_currency_id.id):
227 vals.update({275 vals.update({
228 'debit': subs_account.debit,276 'debit': balance if balance > 0.0 else 0.0,
229 'credit': subs_account.credit,277 'credit': abs(balance) if balance < 0.0 else 0.0,
230 })278 })
231 else:279 else:
232 currency_rate_type = self._currency_rate_type(280 currency_rate_type = self._currency_rate_type(cr, uid, ids,
233 cr, uid, ids, holding_account, context=context)281 holding_account, context=context)
234282
235 currency_value = currency_obj.compute(283 currency_value = currency_obj.compute(cr, uid,
236 cr, uid,284 holding_account.company_currency_id.id,
237 holding_account.company_currency_id.id,285 subs_account.company_currency_id.id,
238 subs_account.company_currency_id.id,286 balance,
239 subs_account.balance,287 currency_rate_type_from=False, # means spot
240 currency_rate_type_from=False, # means spot288 currency_rate_type_to=currency_rate_type,
241 currency_rate_type_to=currency_rate_type,289 context=context)
242 context=context)
243 vals.update({290 vals.update({
244 'currency_id': subs_account.company_currency_id.id,291 'currency_id': subs_account.company_currency_id.id,
245 'amount_currency': subs_account.balance,292 'amount_currency': subs_account.balance,
246 'debit': currency_value > 0 and currency_value or 0.0,293 'debit': currency_value if currency_value > 0.0 else 0.0,
247 'credit': currency_value < 0 and -currency_value or 0.0294 'credit': abs(currency_value) if currency_value < 0.0 else 0.0,
248 })295 })
249296
250 move_line_id = move_line_obj.create(cr, uid, vals, context=context)297 return move_line_obj.create(cr, uid, vals, context=context)
251
252 return move_line_id
253298
254 def reverse_moves(self, cr, uid, ids, subsidiary_id, journal_id,299 def reverse_moves(self, cr, uid, ids, subsidiary_id, journal_id,
255 reversal_date, context=None):300 reversal_date, context=None):
@@ -265,12 +310,11 @@
265 list of IDs of the reversal moves310 list of IDs of the reversal moves
266 """311 """
267 move_obj = self.pool.get('account.move')312 move_obj = self.pool.get('account.move')
268 reversed_ids = move_obj.search(313 reversed_ids = move_obj.search(cr, uid,
269 cr, uid,314 [('journal_id', '=', journal_id),
270 [('journal_id', '=', journal_id),315 ('to_be_reversed', '=', True),
271 ('to_be_reversed', '=', True),316 ('consol_company_id', '=', subsidiary_id)],
272 ('consol_company_id', '=', subsidiary_id)],317 context=context)
273 context=context)
274 reversal_ids = move_obj.create_reversals(318 reversal_ids = move_obj.create_reversals(
275 cr, uid, reversed_ids, reversal_date, context=context)319 cr, uid, reversed_ids, reversal_date, context=context)
276 return reversed_ids, reversal_ids320 return reversed_ids, reversal_ids
@@ -392,25 +436,33 @@
392 date=period.date_stop)436 date=period.date_stop)
393 move_id = move_obj.create(cr, uid, move_vals, context=context)437 move_id = move_obj.create(cr, uid, move_vals, context=context)
394438
395 move_line_ids = []
396 # create a move line per account439 # create a move line per account
440 has_move_line = False
397 for account in accounts:441 for account in accounts:
398 move_line_ids.append(442 m_id = self.consolidate_account(
399 self.consolidate_account(443 cr, uid, ids,
400 cr, uid, ids,444 consolidation_mode,
401 consolidation_mode,445 compute_period_ids,
402 compute_period_ids,446 form.target_move,
403 form.target_move,447 move_id,
404 move_id,448 account.id,
405 account.id,449 subsidiary.id,
406 subsidiary.id,450 context=context)
407 context=context)451 if m_id:
408 )452 has_move_line = True
409453
410 self.create_rate_difference_line(454 if has_move_line:
411 cr, uid, ids, move_id, context=context)455 self.create_rate_difference_line(cr, uid, ids,
412456 move_id, consolidation_mode, context=context)
413 locals()[consolidation_mode + '_move_ids'].append(move_id)457 locals()[consolidation_mode + '_move_ids'].append(move_id)
458
459 else:
460 # We delete created move if it has no line.
461 # As move are generated in draft mode they will be no gap in
462 # number if consolidation journal has correct settings.
463 # I agree it can be more efficient but size of refactoring
464 # is not in ressource scope
465 move_obj.unlink(cr, uid, [move_id])
414466
415 return ytd_move_ids, period_move_ids467 return ytd_move_ids, period_move_ids
416468

Subscribers

People subscribed via source and target branches