[FIX] account: opening entries didn't bring forward the amount in currency when closing a fiscalyear. The centralisation had to take care on that too.
lp bug: https://launchpad.net/bugs/736890 fixed bzr revid: qdp-launchpad@openerp.com-20110621125248-xec0ogl2v1hwxsmo
This commit is contained in:
parent
884aaa8607
commit
016eff262b
|
@ -1331,6 +1331,7 @@ class account_move(osv.osv):
|
|||
|
||||
def _centralise(self, cr, uid, move, mode, context=None):
|
||||
assert mode in ('debit', 'credit'), 'Invalid Mode' #to prevent sql injection
|
||||
currency_obj = self.pool.get('res.currency')
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
|
@ -1381,6 +1382,34 @@ class account_move(osv.osv):
|
|||
cr.execute('SELECT SUM(%s) FROM account_move_line WHERE move_id=%%s AND id!=%%s' % (mode,), (move.id, line_id2))
|
||||
result = cr.fetchone()[0] or 0.0
|
||||
cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
|
||||
|
||||
#adjust also the amount in currency if needed
|
||||
cr.execute("select currency_id, sum(amount_currency) as amount_currency from account_move_line where move_id = %s and currency_id is not null group by currency_id", (move.id,))
|
||||
for row in cr.dictfetchall():
|
||||
currency_id = currency_obj.browse(cr, uid, row['currency_id'], context=context)
|
||||
if not currency_obj.is_zero(cr, uid, currency_id, row['amount_currency']):
|
||||
amount_currency = row['amount_currency'] * -1
|
||||
account_id = amount_currency > 0 and move.journal_id.default_debit_account_id.id or move.journal_id.default_credit_account_id.id
|
||||
cr.execute('select id from account_move_line where move_id=%s and centralisation=\'currency\' and currency_id = %slimit 1', (move.id, row['currency_id']))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
cr.execute('update account_move_line set amount_currency=%s , account_id=%s where id=%s', (amount_currency, account_id, res[0]))
|
||||
else:
|
||||
context.update({'journal_id': move.journal_id.id, 'period_id': move.period_id.id})
|
||||
line_id = self.pool.get('account.move.line').create(cr, uid, {
|
||||
'name': _('Currency Adjustment'),
|
||||
'centralisation': 'currency',
|
||||
'account_id': account_id,
|
||||
'move_id': move.id,
|
||||
'journal_id': move.journal_id.id,
|
||||
'period_id': move.period_id.id,
|
||||
'date': move.period_id.date_stop,
|
||||
'debit': 0.0,
|
||||
'credit': 0.0,
|
||||
'currency_id': row['currency_id'],
|
||||
'amount_currency': amount_currency,
|
||||
}, context)
|
||||
|
||||
return True
|
||||
|
||||
#
|
||||
|
|
|
@ -503,7 +503,7 @@ class account_move_line(osv.osv):
|
|||
}),
|
||||
'date_created': fields.date('Creation date', select=True),
|
||||
'analytic_lines': fields.one2many('account.analytic.line', 'move_id', 'Analytic lines'),
|
||||
'centralisation': fields.selection([('normal','Normal'),('credit','Credit Centralisation'),('debit','Debit Centralisation')], 'Centralisation', size=6),
|
||||
'centralisation': fields.selection([('normal','Normal'),('credit','Credit Centralisation'),('debit','Debit Centralisation'),('currency','Currency Adjustment')], 'Centralisation', size=8),
|
||||
'balance': fields.function(_balance, fnct_search=_balance_search, method=True, string='Balance'),
|
||||
'state': fields.selection([('draft','Unbalanced'), ('valid','Valid')], 'State', readonly=True,
|
||||
help='When new move line is created the state will be \'Draft\'.\n* When all the payments are done it will be in \'Valid\' state.'),
|
||||
|
|
|
@ -103,6 +103,14 @@ class account_fiscalyear_close(osv.osv_memory):
|
|||
if accnt_type_data.close_method=='none' or account.type == 'view':
|
||||
continue
|
||||
if accnt_type_data.close_method=='balance':
|
||||
balance_in_currency = 0.0
|
||||
if account.currency_id:
|
||||
cr.execute('SELECT sum(amount_currency) as balance_in_currency FROM account_move_line ' \
|
||||
'WHERE account_id = %s ' \
|
||||
'AND ' + query_line + ' ' \
|
||||
'AND currency_id = %s', (account.id, account.currency_id.id))
|
||||
balance_in_currency = cr.dictfetchone()['balance_in_currency']
|
||||
|
||||
if abs(account.balance)>0.0001:
|
||||
obj_acc_move_line.create(cr, uid, {
|
||||
'debit': account.balance>0 and account.balance,
|
||||
|
@ -111,7 +119,9 @@ class account_fiscalyear_close(osv.osv_memory):
|
|||
'date': period.date_start,
|
||||
'journal_id': new_journal.id,
|
||||
'period_id': period.id,
|
||||
'account_id': account.id
|
||||
'account_id': account.id,
|
||||
'currency_id': account.currency_id and account.currency_id.id or False,
|
||||
'amount_currency': balance_in_currency,
|
||||
}, {'journal_id': new_journal.id, 'period_id':period.id})
|
||||
if accnt_type_data.close_method == 'unreconciled':
|
||||
offset = 0
|
||||
|
|
Loading…
Reference in New Issue