Skip to Content
Menu
This question has been flagged
2501 Views

Hi,

i would like to consolidate two chart of account (A and B). That mean Chart of account A would be an virtual chart.

I am planning to write an wizar who will help me to set consolidation automaticaly; not manually. The fonction of this wizad will :

-select every account of chart A and set their internal type to "consolidation"

-search accounts who have the same code in the two charts (A and B)

-and then add the account of chart B into child_consol_ids.

So i write this code. 

def consolidate_account(self, cr, uid, ids, holding_account_id, subsidiary_id, context=None):

"""

Consolidates the subsidiary account on the holding account

Creates move lines on the move with id "move_id"

:param holding_account_id: ID of the account to consolidate

(on the holding), the method will

find the subsidiary's corresponding account

:param subsidiary_id: ID of the subsidiary to consolidate

:return: list of IDs of the created move lines

"""

if context is None:

context = {}

account_obj = self.pool.get('account.account')

holding_account = account_obj.browse(cr, uid, holding_account_id,

context=context)

subsidiary_account_id = account_obj.search(cr, uid,

[('code', '=', holding_account.code),

('company_id', '=', subsidiary_id)],

context=context)

if not subsidiary_account_id:

# an account may exist on the holding and not in the subsidiaries,

# nothing to do

return []

browse_ctx = dict(context)

# 1st item because the account's code is unique per company

subs_account = account_obj.browse(cr, uid, subsidiary_account_id[0],

context=browse_ctx)

for account in subs_account:

holding_account.write(cr, uid, {'type' :'consolidation'}, context = context)

holding_account.append(cr,uid,{'child_consol_ids':account.id}, context=context)

return {'type': 'ir.actions.act_window_close'}

Can you help me.

Avatar
Discard