Merge lp:~domsense/domsense-agilebg-addons/adding_account_multiple_currency into lp:domsense-agilebg-addons/6.1

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 148
Proposed branch: lp:~domsense/domsense-agilebg-addons/adding_account_multiple_currency
Merge into: lp:domsense-agilebg-addons/6.1
Diff against target: 333 lines (+306/-0)
5 files modified
account_parallel_currency/AUTHORS.txt (+1/-0)
account_parallel_currency/__init__.py (+22/-0)
account_parallel_currency/__openerp__.py (+45/-0)
account_parallel_currency/account.py (+188/-0)
account_parallel_currency/account_view.xml (+50/-0)
To merge this branch: bzr merge lp:~domsense/domsense-agilebg-addons/adding_account_multiple_currency
Reviewer Review Type Date Requested Status
Agile Business Group Pending
Review via email: mp+93935@code.launchpad.net
To post a comment you must log in.
137. By Lorenzo Battistini

[FIX] authors

138. By Lorenzo Battistini

[MERGE] from parent

139. By Lorenzo Battistini

[MERGE] from parent

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'account_parallel_currency'
2=== added file 'account_parallel_currency/AUTHORS.txt'
3--- account_parallel_currency/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ account_parallel_currency/AUTHORS.txt 2012-02-21 09:16:36 +0000
5@@ -0,0 +1,1 @@
6+Lorenzo Battistini <lorenzo.battistini@agilebg.com>
7
8=== added file 'account_parallel_currency/__init__.py'
9--- account_parallel_currency/__init__.py 1970-01-01 00:00:00 +0000
10+++ account_parallel_currency/__init__.py 2012-02-21 09:16:36 +0000
11@@ -0,0 +1,22 @@
12+# -*- coding: utf-8 -*-
13+##############################################################################
14+#
15+# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
16+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
17+# All Rights Reserved
18+#
19+# This program is free software: you can redistribute it and/or modify
20+# it under the terms of the GNU Affero General Public License as published
21+# by the Free Software Foundation, either version 3 of the License, or
22+# (at your option) any later version.
23+#
24+# This program is distributed in the hope that it will be useful,
25+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+# GNU General Public License for more details.
28+#
29+# You should have received a copy of the GNU Affero General Public License
30+# along with this program. If not, see <http://www.gnu.org/licenses/>.
31+#
32+##############################################################################
33+import account
34
35=== added file 'account_parallel_currency/__openerp__.py'
36--- account_parallel_currency/__openerp__.py 1970-01-01 00:00:00 +0000
37+++ account_parallel_currency/__openerp__.py 2012-02-21 09:16:36 +0000
38@@ -0,0 +1,45 @@
39+# -*- coding: utf-8 -*-
40+##############################################################################
41+#
42+# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
43+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
44+# All Rights Reserved
45+#
46+# This program is free software: you can redistribute it and/or modify
47+# it under the terms of the GNU Affero General Public License as published
48+# by the Free Software Foundation, either version 3 of the License, or
49+# (at your option) any later version.
50+#
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU General Public License for more details.
55+#
56+# You should have received a copy of the GNU Affero General Public License
57+# along with this program. If not, see <http://www.gnu.org/licenses/>.
58+#
59+##############################################################################
60+{
61+ 'name': "Account Parallel Currency",
62+ 'version': '0.1',
63+ 'category': 'Generic Modules/Accounting',
64+ 'description': """
65+ This module handles parallel accounting entries based on different currencies.
66+ It is useful for companies who have to manage accounting with more than one currency at the same time. For instance, companies who have to produce balances on different currencies.
67+
68+ In order to use the module, you have to define one company for each parallel chart of accounts. Then you have to map parallel accounts and parallel journals through the related forms.
69+
70+ When posting new journal entries, the system checks the configured parallel accounts and automatically generates the parallel entries.
71+ """,
72+ 'author': 'Agile Business Group & Domsense',
73+ 'website': 'http://www.agilebg.com',
74+ 'license': 'AGPL-3',
75+ "depends" : ['account'],
76+ "init_xml" : [],
77+ "update_xml" : [
78+ 'account_view.xml',
79+ ],
80+ "demo_xml" : [],
81+ "active": False,
82+ "installable": True
83+}
84
85=== added file 'account_parallel_currency/account.py'
86--- account_parallel_currency/account.py 1970-01-01 00:00:00 +0000
87+++ account_parallel_currency/account.py 2012-02-21 09:16:36 +0000
88@@ -0,0 +1,188 @@
89+# -*- coding: utf-8 -*-
90+##############################################################################
91+#
92+# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
93+# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
94+# All Rights Reserved
95+#
96+# This program is free software: you can redistribute it and/or modify
97+# it under the terms of the GNU Affero General Public License as published
98+# by the Free Software Foundation, either version 3 of the License, or
99+# (at your option) any later version.
100+#
101+# This program is distributed in the hope that it will be useful,
102+# but WITHOUT ANY WARRANTY; without even the implied warranty of
103+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104+# GNU General Public License for more details.
105+#
106+# You should have received a copy of the GNU Affero General Public License
107+# along with this program. If not, see <http://www.gnu.org/licenses/>.
108+#
109+##############################################################################
110+
111+from osv import fields, osv
112+from tools.translate import _
113+import time
114+
115+class account_account(osv.osv):
116+ _inherit = "account.account"
117+
118+ _columns = {
119+ 'parallel_account_ids': fields.many2many('account.account', 'parallel_account_rel', 'child_id',
120+ 'parent_id', 'Parallel Currency Accounts', Help="Set here the accounts you want to automatically move when registering entries in this account"),
121+ 'master_parallel_account_ids': fields.many2many('account.account', 'parallel_account_rel', 'parent_id',
122+ 'child_id', 'Master Parallel Currency Accounts', Help="You can see here the accounts that automatically move this account", readonly=True),
123+ }
124+
125+account_account()
126+
127+class account_move_line(osv.osv):
128+ _inherit = "account.move.line"
129+
130+account_move_line()
131+
132+#and tax codes?
133+class account_move(osv.osv):
134+ _inherit = "account.move"
135+
136+ _columns = {
137+ 'parallel_move_ids': fields.one2many('account.move', 'master_parallel_move_id', 'Parallel Entries',
138+ readonly=True),
139+ 'master_parallel_move_id': fields.many2one('account.move', 'Master Parallel Entry'),
140+ }
141+
142+ def button_cancel(self, cr, uid, ids, context=None):
143+ res = super(account_move, self).button_cancel(cr, uid, ids, context=context)
144+ for move in self.browse(cr, uid, ids, context=context):
145+ for parallel_move in move.parallel_move_ids:
146+ parallel_move.button_cancel(context=context)
147+ parallel_move.unlink(context=context)
148+ return res
149+
150+ def post(self, cr, uid, ids, context=None):
151+ res = super(account_move, self).post(cr, uid, ids, context=context)
152+ if context is None:
153+ context = {}
154+ curr_pool = self.pool.get('res.currency')
155+ for move in self.browse(cr, uid, ids, context=context):
156+ if move.state == 'posted':
157+ new_move_lines = []
158+ parallel_data = {}
159+ for line in move.line_id:
160+ for parallel_account in line.account_id.parallel_account_ids:
161+ parallel_data[parallel_account.company_id.id] = {}
162+ parallel_data[parallel_account.company_id.id]['move_name'] = line.move_id.name
163+ parallel_data[parallel_account.company_id.id]['ref'] = line.move_id.ref
164+ parallel_data[parallel_account.company_id.id]['date'] = line.date
165+ parallel_data[parallel_account.company_id.id]['move_id'] = line.move_id.id
166+
167+ # search period by move date and parallel company
168+ period_ids = self.pool.get('account.period').search(cr, uid, [
169+ ('date_start','<=',line.date),
170+ ('date_stop','>=',line.date ),
171+ ('company_id', '=', parallel_account.company_id.id)])
172+
173+ if len(period_ids) == 0:
174+ raise osv.except_osv(_('Error !'), _('Period %s does not exist in company %s !')
175+ % (line.date, parallel_account.company_id.name))
176+ if len(period_ids) > 1:
177+ raise osv.except_osv(_('Error !'), _('Too many periods %s for company %s !')
178+ % (line.date, parallel_account.company_id.name))
179+
180+ parallel_data[parallel_account.company_id.id]['period_id'] = period_ids[0]
181+
182+ # search parallel journals for the parallel company
183+ parallel_journal_ids = []
184+ for journal in line.journal_id.parallel_journal_ids:
185+ if journal.company_id.id == parallel_account.company_id.id:
186+ parallel_journal_ids.append(journal.id)
187+
188+ if len(parallel_journal_ids) == 0:
189+ raise osv.except_osv(_('Error !'), _('Journal %s does not exist in company %s !')
190+ % (line.journal_id.name, parallel_account.company_id.name))
191+ if len(parallel_journal_ids) > 1:
192+ raise osv.except_osv(_('Error !'), _('Too many journals %s for company %s !')
193+ % (line.journal_id.name, parallel_account.company_id.name))
194+
195+ parallel_data[parallel_account.company_id.id]['journal_id'] = parallel_journal_ids[0]
196+
197+ new_line_values = {
198+ 'name': line.name,
199+ 'date_maturity': line.date_maturity or False,
200+ 'account_id': parallel_account.id,
201+ 'period_id': period_ids[0],
202+ 'journal_id': parallel_journal_ids[0],
203+ 'company_id': parallel_account.company_id.id,
204+ 'partner_id': line.partner_id and line.partner_id.id or False,
205+ }
206+
207+ if line.currency_id and line.amount_currency:
208+ parallel_sec_curr_iso_code = line.currency_id.name
209+ amount = line.amount_currency
210+ else:
211+ parallel_sec_curr_iso_code = line.company_id.currency_id.name
212+ amount = line.debit or ( - line.credit)
213+
214+ # search parallel currency by ISO code and parallel company
215+ parallel_secondary_curr_ids = curr_pool.search(cr, uid, [
216+ ('name', '=', parallel_sec_curr_iso_code),
217+ ('company_id', '=', parallel_account.company_id.id),
218+ ], context=context)
219+
220+ if len(parallel_secondary_curr_ids) == 0:
221+ raise osv.except_osv(_('Error !'), _('Currency %s does not exist in company %s !')
222+ % (parallel_sec_curr_iso_code, parallel_account.company_id.name))
223+ if len(parallel_secondary_curr_ids) > 1:
224+ raise osv.except_osv(_('Error !'), _('Too many currencies %s for company %s !')
225+ % (parallel_sec_curr_iso_code, parallel_account.company_id.name))
226+
227+ # compute parallel base amount from document currency, using move date
228+ context.update({'date': line.date})
229+ parallel_base_amount = curr_pool.compute(cr, uid, parallel_secondary_curr_ids[0],
230+ parallel_account.company_id.currency_id.id, amount,
231+ context=context)
232+
233+ new_line_values['amount_currency'] = amount or False
234+ new_line_values['currency_id'] = parallel_secondary_curr_ids[0]
235+ new_line_values['debit'] = 0.0
236+ new_line_values['credit'] = 0.0
237+ if parallel_base_amount > 0:
238+ new_line_values['debit'] = abs(parallel_base_amount)
239+ elif parallel_base_amount < 0:
240+ new_line_values['credit'] = abs(parallel_base_amount)
241+
242+ new_move_lines.append((parallel_account.company_id.id, (0,0,new_line_values)))
243+ #parallel_data[parallel_account.company_id.id]['move_lines'].append((0,0,new_line_values))
244+
245+ for company_id in parallel_data:
246+ move_lines = []
247+ for new_move_line in new_move_lines:
248+ if new_move_line[0] == company_id:
249+ move_lines.append(new_move_line[1])
250+ move_values = {
251+ 'name': parallel_data[company_id]['move_name'],
252+ 'period_id': parallel_data[company_id]['period_id'],
253+ 'journal_id': parallel_data[company_id]['journal_id'],
254+ 'date': parallel_data[company_id]['date'],
255+ 'company_id': company_id,
256+ 'line_id': move_lines,
257+ 'master_parallel_move_id': parallel_data[company_id]['move_id'],
258+ 'ref': parallel_data[company_id]['ref'],
259+ }
260+ move_id = self.create(cr, uid, move_values, context=context)
261+ self.post(cr, uid, [move_id], context=context)
262+
263+ return res
264+
265+account_move()
266+
267+class account_journal(osv.osv):
268+ _inherit = "account.journal"
269+
270+ _columns = {
271+ 'parallel_journal_ids': fields.many2many('account.journal', 'parallel_journal_rel', 'child_id',
272+ 'parent_id', 'Parallel Currency Journals', Help="Set here the journals you want to automatically move when registering entries in this journal"),
273+ 'master_parallel_journal_ids': fields.many2many('account.journal', 'parallel_journal_rel', 'parent_id',
274+ 'child_id', 'Master Parallel Currency Journals', Help="You can see here the journals that automatically move this journal", readonly=True),
275+ }
276+account_journal()
277
278=== added file 'account_parallel_currency/account_view.xml'
279--- account_parallel_currency/account_view.xml 1970-01-01 00:00:00 +0000
280+++ account_parallel_currency/account_view.xml 2012-02-21 09:16:36 +0000
281@@ -0,0 +1,50 @@
282+<?xml version="1.0" encoding="utf-8"?>
283+<openerp>
284+ <data>
285+ <record id="view_account_form" model="ir.ui.view">
286+ <field name="name">account.account.form</field>
287+ <field name="model">account.account</field>
288+ <field name="type">form</field>
289+ <field name="inherit_id" ref="account.view_account_form"></field>
290+ <field name="arch" type="xml">
291+ <page string="Notes" position="after">
292+ <page string="Parallel Currency">
293+ <separator string="Parallel Currency Accounts" colspan="4"/>
294+ <field colspan="4" name="parallel_account_ids" nolabel="1" domain="[('company_id', '!=', company_id)]"/>
295+ <separator string="Master Parallel Currency Accounts" colspan="4"/>
296+ <field colspan="4" name="master_parallel_account_ids" nolabel="1"/>
297+ </page>
298+ </page>
299+ </field>
300+ </record>
301+ <record id="view_account_journal_form" model="ir.ui.view">
302+ <field name="name">view_account_journal_form</field>
303+ <field name="model">account.journal</field>
304+ <field name="type">form</field>
305+ <field name="inherit_id" ref="account.view_account_journal_form"></field>
306+ <field name="arch" type="xml">
307+ <page string="Entry Controls" position="after">
308+ <page string="Parallel Currency">
309+ <separator string="Parallel Currency Journals" colspan="4"/>
310+ <field colspan="4" name="parallel_journal_ids" nolabel="1" domain="[('company_id', '!=', company_id)]"/>
311+ <separator string="Master Parallel Currency Journals" colspan="4"/>
312+ <field colspan="4" name="master_parallel_journal_ids" nolabel="1"/>
313+ </page>
314+ </page>
315+ </field>
316+ </record>
317+ <record id="view_move_form" model="ir.ui.view">
318+ <field name="name">view_move_form</field>
319+ <field name="model">account.move</field>
320+ <field name="type">form</field>
321+ <field name="inherit_id" ref="account.view_move_form"></field>
322+ <field name="arch" type="xml">
323+ <page string="Journal Items" position="after">
324+ <page string="Parallel Entries">
325+ <field colspan="4" name="parallel_move_ids" nolabel="1" />
326+ </page>
327+ </page>
328+ </field>
329+ </record>
330+ </data>
331+</openerp>
332
333=== added directory 'account_parallel_currency/i18n'

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: