Allow bank statement in different currency than the company one
- add currency on journal - add currency in statement view - convert the amount to the right currency - improve creation of move line bzr revid: ced-f524e19c17528b18fe27b10845780b6e35e83c67
This commit is contained in:
parent
675fd5e924
commit
74ccdc852e
|
@ -383,6 +383,7 @@ class account_journal(osv.osv):
|
|||
'sequence_id': fields.many2one('ir.sequence', 'Entry Sequence', help="The sequence gives the display order for a list of journals", required=True),
|
||||
'user_id': fields.many2one('res.users', 'User', help="The responsible user of this journal"),
|
||||
'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'),
|
||||
'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
|
|
|
@ -52,19 +52,33 @@ class account_bank_statement(osv.osv):
|
|||
return self.browse(cr, uid, [res[0]], context)[0].balance_end
|
||||
return 0.0
|
||||
|
||||
def _end_balance(self, cr, uid, ids, prop, unknow_none, unknow_dict):
|
||||
def _end_balance(self, cursor, user, ids, name, attr, context=None):
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
res = {}
|
||||
statements = self.browse(cr, uid, ids)
|
||||
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
|
||||
statements = self.browse(cursor, user, ids, context=context)
|
||||
for statement in statements:
|
||||
res[statement.id] = statement.balance_start
|
||||
currency_id = statement.currency.id
|
||||
for line in statement.move_line_ids:
|
||||
if line.debit>0:
|
||||
if line.account_id.id == (statement.journal_id.default_debit_account_id.id):
|
||||
res[statement.id]+=line.debit
|
||||
if line.debit > 0:
|
||||
if line.account_id.id == \
|
||||
statement.journal_id.default_debit_account_id.id:
|
||||
res[statement.id] += res_currency_obj.compute(cursor,
|
||||
user, company_currency_id, currency_id,
|
||||
line.debit, context=context)
|
||||
else:
|
||||
if line.account_id.id == (statement.journal_id.default_credit_account_id.id):
|
||||
res[statement.id]+=line.credit
|
||||
if statement.state=='draft':
|
||||
if line.account_id.id == \
|
||||
statement.journal_id.default_credit_account_id.id:
|
||||
res[statement.id] += res_currency_obj.compute(cursor,
|
||||
user, company_currency_id, currency_id,
|
||||
line.credit, context=context)
|
||||
if statement.state == 'draft':
|
||||
for line in statement.line_ids:
|
||||
res[statement.id] += line.amount
|
||||
for r in res:
|
||||
|
@ -78,58 +92,113 @@ class account_bank_statement(osv.osv):
|
|||
else:
|
||||
return False
|
||||
|
||||
def _currency(self, cursor, user, ids, name, args, context=None):
|
||||
res = {}
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
default_currency = res_users_obj.browse(cursor, user,
|
||||
user, context=context).company_id.currency_id
|
||||
for statement in self.browse(cursor, user, ids, context=context):
|
||||
currency = statement.journal_id.currency
|
||||
if not currency:
|
||||
currency = default_currency
|
||||
res[statement.id] = currency.id
|
||||
currency_names = {}
|
||||
for currency_id, currency_name in res_currency_obj.name_get(cursor,
|
||||
user, [x for x in res.values()], context=context):
|
||||
currency_names[currency_id] = currency_name
|
||||
for statement_id in res.keys():
|
||||
currency_id = res[statement_id]
|
||||
res[statement_id] = (currency_id, currency_names[currency_id])
|
||||
return res
|
||||
|
||||
_order = "date desc"
|
||||
_name = "account.bank.statement"
|
||||
_description = "Bank Statement"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'date': fields.date('Date', required=True, states={'confirm':[('readonly',True)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'confirm':[('readonly',True)]}, domain=[('type','=','cash')]),
|
||||
'period_id': fields.many2one('account.period', 'Period', required=True, states={'confirm':[('readonly',True)]}),
|
||||
'balance_start': fields.float('Starting Balance', digits=(16,2), states={'confirm':[('readonly',True)]}),
|
||||
'balance_end_real': fields.float('Ending Balance', digits=(16,2), states={'confirm':[('readonly',True)]}),
|
||||
'date': fields.date('Date', required=True,
|
||||
states={'confirm': [('readonly', True)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True,
|
||||
states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'cash')]),
|
||||
'period_id': fields.many2one('account.period', 'Period', required=True,
|
||||
states={'confirm':[('readonly', True)]}),
|
||||
'balance_start': fields.float('Starting Balance', digits=(16,2),
|
||||
states={'confirm':[('readonly',True)]}),
|
||||
'balance_end_real': fields.float('Ending Balance', digits=(16,2),
|
||||
states={'confirm':[('readonly', True)]}),
|
||||
'balance_end': fields.function(_end_balance, method=True, string='Balance'),
|
||||
'line_ids': fields.one2many('account.bank.statement.line', 'statement_id', 'Statement lines', states={'confirm':[('readonly',True)]}),
|
||||
'move_line_ids': fields.one2many('account.move.line', 'statement_id', 'Entry lines', states={'confirm':[('readonly',True)]}),
|
||||
'state': fields.selection([('draft','Draft'),('confirm','Confirm')], 'State', required=True, states={'confirm':[('readonly',True)]}, readonly="1"),
|
||||
'line_ids': fields.one2many('account.bank.statement.line',
|
||||
'statement_id', 'Statement lines',
|
||||
states={'confirm':[('readonly', True)]}),
|
||||
'move_line_ids': fields.one2many('account.move.line', 'statement_id',
|
||||
'Entry lines', states={'confirm':[('readonly',True)]}),
|
||||
'state': fields.selection([('draft', 'Draft'),('confirm', 'Confirm')],
|
||||
'State', required=True,
|
||||
states={'confirm': [('readonly', True)]}, readonly="1"),
|
||||
'currency': fields.function(_currency, method=True, string='Currency',
|
||||
type='many2one', relation='res.currency'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement'),
|
||||
'name': lambda self, cr, uid, context=None: \
|
||||
self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement'),
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'state': lambda *a: 'draft',
|
||||
'balance_start': _default_balance_start,
|
||||
'journal_id': _default_journal_id,
|
||||
'period_id': _get_period,
|
||||
}
|
||||
def button_confirm(self, cr, uid, ids, context={}):
|
||||
|
||||
def button_confirm(self, cr, uid, ids, context=None):
|
||||
done = []
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
account_move_obj = self.pool.get('account.move')
|
||||
account_move_line_obj = self.pool.get('account.move.line')
|
||||
account_bank_statement_line_obj = \
|
||||
self.pool.get('account.bank.statement.line')
|
||||
|
||||
company_currency_id = res_users_obj.browse(cr, uid, uid,
|
||||
context=context).company_id.currency_id.id
|
||||
|
||||
for st in self.browse(cr, uid, ids, context):
|
||||
if not st.state=='draft':
|
||||
continue
|
||||
|
||||
if not (abs(st.balance_end - st.balance_end_real) < 0.0001):
|
||||
raise osv.except_osv('Error !', 'The statement balance is incorrect !\nCheck that the ending balance equals the computed one.')
|
||||
if (not st.journal_id.default_credit_account_id) or (not st.journal_id.default_debit_account_id):
|
||||
raise osv.except_osv('Configration Error !', 'Please verify that an account is defined in the journal.')
|
||||
raise osv.except_osv('Error !',
|
||||
'The statement balance is incorrect !\n'
|
||||
'Check that the ending balance equals the computed one.')
|
||||
if (not st.journal_id.default_credit_account_id) \
|
||||
or (not st.journal_id.default_debit_account_id):
|
||||
raise osv.except_osv('Configration Error !',
|
||||
'Please verify that an account is defined in the journal.')
|
||||
|
||||
for line in st.move_line_ids:
|
||||
if line.state <> 'valid':
|
||||
raise osv.except_osv('Error !', 'The account entries lines are not valid.')
|
||||
raise osv.except_osv('Error !',
|
||||
'The account entries lines are not valid.')
|
||||
|
||||
for move in st.line_ids:
|
||||
move_id = self.pool.get('account.move').create(cr, uid, {
|
||||
move_id = account_move_obj.create(cr, uid, {
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': st.period_id.id,
|
||||
}, context=context)
|
||||
self.pool.get('account.bank.statement.line').write(cr, uid, [move.id], {
|
||||
account_bank_statement_line_obj.write(cr, uid, [move.id], {
|
||||
'move_ids': [(4,move_id, False)]
|
||||
})
|
||||
if not move.amount:
|
||||
continue
|
||||
|
||||
torec = []
|
||||
amount = move.amount
|
||||
amount = res_currency_obj.compute(cr, uid, st.currency.id,
|
||||
company_currency_id, move.amount, context=context)
|
||||
if move.reconcile_id and move.reconcile_id.line_new_ids:
|
||||
for newline in move.reconcile_id.line_new_ids:
|
||||
amount += newline.amount
|
||||
torec.append(self.pool.get('account.move.line').create(cr, uid, {
|
||||
|
||||
torec.append(account_move_line_obj.create(cr, uid, {
|
||||
'name': move.name,
|
||||
'date': move.date,
|
||||
'ref': move.ref,
|
||||
|
@ -142,9 +211,10 @@ class account_bank_statement(osv.osv):
|
|||
'journal_id': st.journal_id.id,
|
||||
'period_id': st.period_id.id,
|
||||
}, context=context))
|
||||
|
||||
if move.reconcile_id and move.reconcile_id.line_new_ids:
|
||||
for newline in move.reconcile_id.line_new_ids:
|
||||
self.pool.get('account.move.line').create(cr, uid, {
|
||||
account_move_line_obj.create(cr, uid, {
|
||||
'name': newline.name or move.name,
|
||||
'date': move.date,
|
||||
'ref': move.ref,
|
||||
|
@ -158,29 +228,56 @@ class account_bank_statement(osv.osv):
|
|||
'period_id': st.period_id.id,
|
||||
}, context=context)
|
||||
|
||||
c = context.copy()
|
||||
c['journal_id'] = st.journal_id.id
|
||||
c['period_id'] = st.period_id.id
|
||||
fields = ['move_id','name','date','partner_id','account_id','credit','debit']
|
||||
default = self.pool.get('account.move.line').default_get(cr, uid, fields, context=c)
|
||||
default.update({
|
||||
amount = res_currency_obj.compute(cr, uid, st.currency.id,
|
||||
company_currency_id, move.amount, context=context)
|
||||
if amount >= 0:
|
||||
account_id = st.journal_id.default_credit_account_id.id
|
||||
else:
|
||||
account_id = st.journal_id.default_debit_account_id.id
|
||||
|
||||
# Fill the secondary amount/currency
|
||||
# if currency is not the same than the company
|
||||
amount_currency = False
|
||||
currency_id = False
|
||||
if st.currency.id <> company_currency_id:
|
||||
amount_currency = move.amount
|
||||
currency_id = st.currency.id
|
||||
|
||||
account_move_line_obj.create(cr, uid, {
|
||||
'name': move.name,
|
||||
'date': move.date,
|
||||
'ref': move.ref,
|
||||
'move_id': move_id,
|
||||
'partner_id': ((move.partner_id) and move.partner_id.id) or False,
|
||||
'account_id': account_id,
|
||||
'credit': ((amount < 0) and -amount) or 0.0,
|
||||
'debit': ((amount > 0) and amount) or 0.0,
|
||||
'statement_id': st.id,
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': st.period_id.id,
|
||||
'move_id': move_id,
|
||||
'ref': move.ref,
|
||||
})
|
||||
self.pool.get('account.move.line').create(cr, uid, default, context=context)
|
||||
'amount_currency': amount_currency,
|
||||
'currency_id': currency_id,
|
||||
}, context=context)
|
||||
|
||||
for line in account_move_line_obj.browse(cr, uid, [x.id for x in
|
||||
account_move_obj.browse(cr, uid, move_id,
|
||||
context=context).line_id],
|
||||
context=context):
|
||||
if line.state <> 'valid':
|
||||
raise osv.except_osv('Error !',
|
||||
'Account move line "%s" is not valid' % line.name)
|
||||
|
||||
if move.reconcile_id and move.reconcile_id.line_ids:
|
||||
torec += map(lambda x: x.id, move.reconcile_id.line_ids)
|
||||
try:
|
||||
self.pool.get('account.move.line').reconcile(cr, uid, torec, 'statement', context)
|
||||
account_move_line_obj.reconcile(cr, uid, torec, 'statement', context)
|
||||
except:
|
||||
raise osv.except_osv('Error !', 'Unable to reconcile entry "%s": %.2f'%(move.name, move.amount))
|
||||
|
||||
done.append(st.id)
|
||||
self.write(cr, uid, done, {'state':'confirm'}, context=context)
|
||||
return True
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context={}):
|
||||
done = []
|
||||
for st in self.browse(cr, uid, ids, context):
|
||||
|
@ -193,64 +290,171 @@ class account_bank_statement(osv.osv):
|
|||
done.append(st.id)
|
||||
self.write(cr, uid, done, {'state':'draft'}, context=context)
|
||||
return True
|
||||
def onchange_journal_id(self, cr, uid, id, journal_id, context={}):
|
||||
|
||||
def onchange_journal_id(self, cursor, user, statement_id, journal_id, context=None):
|
||||
if not journal_id:
|
||||
return {}
|
||||
cr.execute('select balance_end_real from account_bank_statement where journal_id=%d order by date desc limit 1', (journal_id,))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
return {'value': {'balance_start': res[0] or 0.0}}
|
||||
return {}
|
||||
return {'value': {'currency': False}}
|
||||
|
||||
account_journal_obj = self.pool.get('account.journal')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
|
||||
cursor.execute('SELECT balance_end_real \
|
||||
FROM account_bank_statement \
|
||||
WHERE journal_id = %d \
|
||||
ORDER BY date DESC LIMIT 1', (journal_id,))
|
||||
res = cursor.fetchone()
|
||||
balance_start = res and res[0] or 0.0
|
||||
|
||||
currency_id = account_journal_obj.browse(cursor, user, journal_id,
|
||||
context=context).currency.id
|
||||
if not currency_id:
|
||||
currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
currency = res_currency_obj.name_get(cursor, user, [currency_id],
|
||||
context=context)[0]
|
||||
return {'value': {'balance_start': balance_start, 'currency': currency}}
|
||||
|
||||
account_bank_statement()
|
||||
|
||||
|
||||
class account_bank_statement_reconcile(osv.osv):
|
||||
_name = "account.bank.statement.reconcile"
|
||||
_description = "Statement reconcile"
|
||||
def _total_entry(self, cr, uid, ids, prop, unknow_none, context={}):
|
||||
|
||||
def _total_entry(self, cursor, user, ids, name, attr, context=None):
|
||||
result = {}
|
||||
for o in self.browse(cr, uid, ids, context):
|
||||
for o in self.browse(cursor, user, ids, context=context):
|
||||
result[o.id] = 0.0
|
||||
for line in o.line_ids:
|
||||
result[o.id] += line.debit - line.credit
|
||||
return result
|
||||
|
||||
def _total_new(self, cr, uid, ids, prop, unknow_none, context={}):
|
||||
def _total_new(self, cursor, user, ids, name, attr, context=None):
|
||||
result = {}
|
||||
for o in self.browse(cr, uid, ids, context):
|
||||
for o in self.browse(cursor, user, ids, context=context):
|
||||
result[o.id] = 0.0
|
||||
for line in o.line_new_ids:
|
||||
result[o.id] += line.amount
|
||||
return result
|
||||
|
||||
def _total_balance(self, cr, uid, ids, prop, unknow_none, context={}):
|
||||
def _total_balance(self, cursor, user, ids, name, attr, context=None):
|
||||
result = {}
|
||||
for o in self.browse(cr, uid, ids, context):
|
||||
result[o.id] = o.total_new-o.total_entry+o.total_amount
|
||||
for o in self.browse(cursor, user, ids, context=context):
|
||||
result[o.id] = o.total_new - o.total_entry + o.total_amount
|
||||
return result
|
||||
|
||||
def _total_amount(self, cr, uid, ids, prop, unknow_none, context={}):
|
||||
return dict(map(lambda x: (x,context.get('amount', 0.0)), ids))
|
||||
def _total_amount(self, cursor, user, ids, name, attr, context=None):
|
||||
res = {}
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
def name_get(self, cr, uid, ids, context):
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
currency_id = context.get('currency_id', company_currency_id)
|
||||
|
||||
for reconcile_id in ids:
|
||||
res[reconcile_id] = res_currency_obj.compute(cursor, user,
|
||||
currency_id, company_currency_id,
|
||||
context.get('amount', 0.0), context=context)
|
||||
return res
|
||||
|
||||
def _default_amount(self, cursor, user, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
currency_id = context.get('currency_id', company_currency_id)
|
||||
|
||||
return res_currency_obj.compute(cursor, user,
|
||||
currency_id, company_currency_id,
|
||||
context.get('amount', 0.0), context=context)
|
||||
|
||||
def _total_currency(self, cursor, user, ids, name, attrs, context=None):
|
||||
res = {}
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
|
||||
for reconcile_id in ids:
|
||||
res[reconcile_id] = company_currency_id
|
||||
return res
|
||||
|
||||
def _default_currency(self, cursor, user, context=None):
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
return res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
|
||||
|
||||
def _total_second_amount(self, cursor, user, ids, name, attr,
|
||||
context=None):
|
||||
res = {}
|
||||
for reconcile_id in ids:
|
||||
res[reconcile_id] = context.get('amount', 0.0)
|
||||
return res
|
||||
|
||||
def _total_second_currency(self, cursor, user, ids, name, attr, context=None):
|
||||
res = {}
|
||||
for reconcile_id in ids:
|
||||
res[reconcile_id] = context.get('currency_id', False)
|
||||
return res
|
||||
|
||||
def name_get(self, cursor, user, ids, context=None):
|
||||
res= []
|
||||
for o in self.browse(cr, uid, ids, context):
|
||||
res.append((o.id, '[%.2f/%.2f]' % (o.total_entry, o.total_new)))
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
currency_id = context.get('currency_id', company_currency_id)
|
||||
|
||||
for o in self.browse(cursor, user, ids, context=context):
|
||||
res.append((o.id, '[%.2f/%.2f]' % (
|
||||
res_currency_obj.compute(cursor, user, company_currency_id,
|
||||
currency_id, o.total_entry, context=context),
|
||||
res_currency_obj.compute(cursor, user, company_currency_id,
|
||||
currency_id, o.total_new, context=context))))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Date', size=64, required=True),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
|
||||
'line_new_ids': fields.one2many('account.bank.statement.reconcile.line', 'line_id', 'Write-Off'),
|
||||
'total_entry': fields.function(_total_entry, method=True, string='Total entries'),
|
||||
'total_new': fields.function(_total_new, method=True, string='Total write-off'),
|
||||
'total_amount': fields.function(_total_amount, method=True, string='Payment amount'),
|
||||
'total_balance': fields.function(_total_balance, method=True, string='Balance'),
|
||||
'line_new_ids': fields.one2many('account.bank.statement.reconcile.line',
|
||||
'line_id', 'Write-Off'),
|
||||
'total_entry': fields.function(_total_entry, method=True,
|
||||
string='Total entries'),
|
||||
'total_new': fields.function(_total_new, method=True,
|
||||
string='Total write-off'),
|
||||
'total_second_amount': fields.function(_total_second_amount,
|
||||
method=True, string='Payment amount',
|
||||
help='The amount in the currency of the journal'),
|
||||
'total_second_currency': fields.function(_total_second_currency, method=True,
|
||||
string='Currency', type='many2one', relation='res.currency',
|
||||
help='The currency of the journal'),
|
||||
'total_amount': fields.function(_total_amount, method=True,
|
||||
string='Payment amount'),
|
||||
'total_currency': fields.function(_total_currency, method=True,
|
||||
string='Currency', type='many2one', relation='res.currency'),
|
||||
'total_balance': fields.function(_total_balance, method=True,
|
||||
string='Balance'),
|
||||
#line_ids define in account.py
|
||||
}
|
||||
_defaults = {
|
||||
'name': lambda *a:time.strftime('%Y-%m-%d'),
|
||||
'partner_id': lambda s,cr,u,c={}: c.get('partner', False),
|
||||
'total_amount': lambda s,cr,u,c={}: c.get('amount', 0.0)
|
||||
'name': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'partner_id': lambda obj, cursor, user, context=None: \
|
||||
context.get('partner', False),
|
||||
'total_amount': _default_amount,
|
||||
'total_currency': _default_currency,
|
||||
'total_second_amount': lambda obj, cursor, user, context=None: \
|
||||
context.get('amount', 0.0),
|
||||
'total_second_currency': lambda obj, cursor, user, context=None: \
|
||||
context.get('currency_id', False),
|
||||
'total_balance': _default_amount,
|
||||
}
|
||||
account_bank_statement_reconcile()
|
||||
|
||||
|
@ -267,18 +471,36 @@ account_bank_statement_reconcile_line()
|
|||
|
||||
|
||||
class account_bank_statement_line(osv.osv):
|
||||
def onchange_partner_id(self, cr, uid, id, partner_id, type, context={}):
|
||||
|
||||
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,
|
||||
context={}):
|
||||
if not partner_id:
|
||||
return {}
|
||||
part = self.pool.get('res.partner').browse(cr, uid, partner_id, context)
|
||||
if type=='supplier':
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
res_users_obj = self.pool.get('res.users')
|
||||
|
||||
company_currency_id = res_users_obj.browse(cursor, user, user,
|
||||
context=context).company_id.currency_id.id
|
||||
|
||||
part = self.pool.get('res.partner').browse(cursor, user, partner_id,
|
||||
context=context)
|
||||
if type == 'supplier':
|
||||
account_id = part.property_account_payable.id
|
||||
else:
|
||||
account_id = part.property_account_receivable.id
|
||||
cr.execute('select sum(debit-credit) from account_move_line where (reconcile_id is null) and partner_id=%d and account_id=%d', (partner_id, account_id))
|
||||
balance = cr.fetchone()[0] or 0.0
|
||||
val = {'amount': balance, 'account_id':account_id}
|
||||
return {'value':val}
|
||||
|
||||
cursor.execute('SELECT sum(debit-credit) \
|
||||
FROM account_move_line \
|
||||
WHERE (reconcile_id is null) \
|
||||
AND partner_id = %d \
|
||||
AND account_id=%d', (partner_id, account_id))
|
||||
res = cursor.fetchone()
|
||||
balance = res and res[0] or 0.0
|
||||
|
||||
balance = res_currency_obj.compute(cursor, user, company_currency_id,
|
||||
currency_id, balance, context=context)
|
||||
return {'value': {'amount': balance, 'account_id': account_id}}
|
||||
|
||||
_order = "date,name desc"
|
||||
_name = "account.bank.statement.line"
|
||||
_description = "Bank Statement Line"
|
||||
|
@ -300,6 +522,7 @@ class account_bank_statement_line(osv.osv):
|
|||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'type': lambda *a: 'general',
|
||||
}
|
||||
|
||||
account_bank_statement_line()
|
||||
|
||||
|
||||
|
|
|
@ -266,6 +266,7 @@
|
|||
<field name="sequence_id"/>
|
||||
<field name="default_debit_account_id"/>
|
||||
<field name="default_credit_account_id"/>
|
||||
<field name="currency"/>
|
||||
<field name="user_id"/>
|
||||
<newline/>
|
||||
<field name="centralisation"/>
|
||||
|
@ -315,7 +316,9 @@
|
|||
<field name="name" select="1"/>
|
||||
<field name="date" select="1"/>
|
||||
<field name="journal_id" select="1" on_change="onchange_journal_id(journal_id)"/>
|
||||
<field name="currency"/>
|
||||
<field name="period_id" select="2"/>
|
||||
<newline/>
|
||||
<field name="balance_start"/>
|
||||
<field name="balance_end_real"/>
|
||||
<notebook colspan="4">
|
||||
|
@ -326,17 +329,20 @@
|
|||
<field name="ref"/>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,type)"/>
|
||||
<field name="account_id" domain="[('journal_id','=',parent.journal_id)]"/>
|
||||
<field name="partner_id"
|
||||
on_change="onchange_partner_id(partner_id, type, parent.currency)"/>
|
||||
<field name="account_id"
|
||||
domain="[('journal_id','=',parent.journal_id)]"/>
|
||||
<field name="amount"/>
|
||||
<field name="reconcile_id" context="{'partner_id':partner_id,'amount':amount,'account_id':account_id}"/>
|
||||
<field name="reconcile_id"
|
||||
context="{'partner_id': partner_id, 'amount': amount, 'account_id': account_id, 'currency_id': parent.currency}"/>
|
||||
</tree>
|
||||
<form string="Statement lines">
|
||||
<field name="date"/>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,type)"/>
|
||||
<field name="account_id" domain="[('journal_id','=',parent.journal_id), ('type', '<>', 'view')]"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id, type)"/>
|
||||
<field name="account_id" domain="[('journal_id', '=', parent.journal_id), ('type', '<>', 'view')]"/>
|
||||
<field name="amount"/>
|
||||
<field name="reconcile_id" context="{'partner_id':partner_id,'amount':amount,'account_id':account_id}"/>
|
||||
<field name="ref"/>
|
||||
|
@ -344,7 +350,8 @@
|
|||
<field name="note" nolabel="1" colspan="4"/>
|
||||
</form>
|
||||
</field>
|
||||
</page><page string="Real Entries">
|
||||
</page>
|
||||
<page string="Real Entries">
|
||||
<field name="move_line_ids" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
|
@ -384,10 +391,19 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Reconcile">
|
||||
<field name="name" select="1"/>
|
||||
<newline/>
|
||||
<field name="total_second_amount"/>
|
||||
<field name="total_second_currency"/>
|
||||
<newline/>
|
||||
<field name="total_amount"/>
|
||||
<field name="total_currency"/>
|
||||
<newline/>
|
||||
<separator colspan="4" string="Entries"/>
|
||||
<field name="line_ids" view_mode="tree" colspan="4" nolabel="1" domain="[('partner_id','=',context.get('partner_id', False)),('state','=','valid'),('account_id','=',context.get('account_id', False)),('reconcile_id', '=', False)]">
|
||||
</field>
|
||||
<field name="line_ids"
|
||||
view_mode="tree"
|
||||
colspan="4"
|
||||
nolabel="1"
|
||||
domain="[('partner_id','=',context.get('partner_id', False)),('state','=','valid'),('account_id','=',context.get('account_id', False)),('reconcile_id', '=', False)]"/>
|
||||
<field name="line_new_ids" colspan="4" nolabel="1">
|
||||
<tree string="Write-Off" editable="bottom">
|
||||
<field name="account_id"/>
|
||||
|
|
Loading…
Reference in New Issue