[MIG]FIX formatting

pull/268/head
Sandip Mangukiya 2017-05-31 23:16:39 +05:30 committed by Murtuza Saleh
parent 7bcc254c25
commit e624c95322
7 changed files with 481 additions and 236 deletions

View File

@ -8,7 +8,8 @@
"version": "10.0.1.0.0", "version": "10.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Accounting and Financial Management", "category": "Accounting and Financial Management",
"author": "NovaPoint Group LLC, Ursa Information Systems, Odoo Community Association (OCA)", "author": "NovaPoint Group LLC, Ursa Information Systems, "
"Odoo Community Association (OCA)",
"website": "http://www.novapointgroup.com", "website": "http://www.novapointgroup.com",
"depends": [ "depends": [
"account_voucher", "account_voucher",

View File

@ -4,4 +4,5 @@
# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>) # Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_move_line, account_banking_reconciliation from . import account_move_line
from . import account_banking_reconciliation

View File

@ -12,78 +12,97 @@ from operator import itemgetter
from odoo.tools.float_utils import float_round from odoo.tools.float_utils import float_round
class bank_acc_rec_statement(models.Model): class BankAccRecStatement(models.Model):
@api.multi @api.multi
def check_group(self): def check_group(self):
"""Check if following security constraints are implemented for groups: """Check if following security constraints are implemented for groups:
Bank Statement Preparer they can create, view and delete any of the Bank Statements provided the Bank Statement is not in the DONE state, Bank Statement Preparer they can create, view and delete any of the
Bank Statements provided the Bank Statement is not in the DONE state,
or the Ready for Review state. or the Ready for Review state.
Bank Statement Verifier they can create, view, edit, and delete any of the Bank Statements information at any time. Bank Statement Verifier they can create, view, edit, and delete any
NOTE: DONE Bank Statements are only allowed to be deleted by a Bank Statement Verifier.""" of the Bank Statements information at any time.
NOTE: DONE Bank Statements are only allowed to be deleted by a
Bank Statement Verifier."""
model_data_obj = self.env['ir.model.data'] model_data_obj = self.env['ir.model.data']
res_groups_obj = self.env['res.groups'] res_groups_obj = self.env['res.groups']
group_verifier_id = model_data_obj._get_id('account_banking_reconciliation', 'group_bank_stmt_verifier') group_verifier_id = model_data_obj._get_id(
'account_banking_reconciliation',
'group_bank_stmt_verifier')
for statement in self: for statement in self:
if group_verifier_id: if group_verifier_id:
res_id = model_data_obj.browse(group_verifier_id).res_id res_id = model_data_obj.browse(group_verifier_id).res_id
group_verifier = res_groups_obj.browse([res_id]) group_verifier = res_groups_obj.browse([res_id])
group_user_ids = [user.id for user in group_verifier.users] group_user_ids = [user.id for user in group_verifier.users]
if statement.state!='draft' and self.env.uid not in group_user_ids: if statement.state != 'draft' and \
raise UserError(_("Only a member of '%s' group may delete/edit bank statements when not in draft state!" %(group_verifier.name))) self.env.uid not in group_user_ids:
raise UserError(_("Only a member of '%s' "
"group may delete/edit "
"bank statements when not in draft "
"state!" % (group_verifier.name)))
return True return True
@api.model @api.model
def copy(self, default={}): def copy(self, default=None):
if default is None:
default = {}
default.update({ default.update({
'credit_move_line_ids': [], 'credit_move_line_ids': [],
'debit_move_line_ids': [], 'debit_move_line_ids': [],
'name': '', 'name': '',
}) })
return super(bank_acc_rec_statement, self).copy(default=default) return super(BankAccRecStatement, self).copy(default=default)
@api.multi @api.multi
def write(self, vals): def write(self, vals):
self.check_group() # Check if the user is allowed to perform the action # Check if the user is allowed to perform the action
return super(bank_acc_rec_statement, self).write(vals) self.check_group()
return super(BankAccRecStatement, self).write(vals)
@api.model @api.model
def unlink(self): def unlink(self):
"Reset the related account.move.line to be re-assigned later to statement." """Reset the related account.move.line to be re-assigned later
to statement."""
statement_line_obj = self.env['bank.acc.rec.statement.line'] statement_line_obj = self.env['bank.acc.rec.statement.line']
self.check_group() # Check if the user is allowed to perform the action self.check_group() # Check if user is allowed to perform the action
for statement in self: for statement in self:
statement_lines = statement.credit_move_line_ids + statement.debit_move_line_ids statement_lines = statement.credit_move_line_ids + \
statement.debit_move_line_ids
statement_line_ids = map(lambda x: x.id, statement_lines) statement_line_ids = map(lambda x: x.id, statement_lines)
statement_line_brws = statement_line_obj.browse(statement_line_ids) statement_line_brws = statement_line_obj.browse(statement_line_ids)
statement_line_brws.unlink() # call unlink method to reset statement_line_brws.unlink() # call unlink method to reset
return super(bank_acc_rec_statement, self).unlink() return super(BankAccRecStatement, self).unlink()
@api.multi @api.multi
def check_difference_balance(self): def check_difference_balance(self):
"Check if difference balance is zero or not." # Check if difference balance is zero or not.
for statement in self: for statement in self:
if statement.cleared_balance_cur: if statement.cleared_balance_cur:
if statement.difference_cur != 0.0: if statement.difference_cur != 0.0:
raise UserError(_("Prior to reconciling a statement, all differences must be accounted for and the Difference balance must be zero." \ raise UserError(_("Prior to reconciling a statement, "
" Please review and make necessary changes.")) "all differences must be accounted for "
"and the Difference balance must be "
"zero. Please review "
"and make necessary changes."))
else: else:
if statement.difference != 0.0: if statement.difference != 0.0:
raise UserError(_("Prior to reconciling a statement, all differences must be accounted for and the Difference balance must be zero." \ raise UserError(_("Prior to reconciling a statement, "
" Please review and make necessary changes.")) "all differences must be accounted for "
"and the Difference balance must "
"be zero. Please review "
"and make necessary changes."))
return True return True
@api.multi @api.multi
def action_cancel(self): def action_cancel(self):
"Cancel the the statement." """Cancel the the statement."""
self.write({'state': 'cancel'}) self.write({'state': 'cancel'})
return True return True
@api.multi @api.multi
def action_review(self): def action_review(self):
"Change the status of statement from 'draft' to 'to_be_reviewed'." """Change the status of statement from 'draft' to 'to_be_reviewed'."""
# If difference balance not zero prevent further processing # If difference balance not zero prevent further processing
self.check_difference_balance() self.check_difference_balance()
self.write({'state': 'to_be_reviewed'}) self.write({'state': 'to_be_reviewed'})
@ -91,57 +110,70 @@ class bank_acc_rec_statement(models.Model):
@api.multi @api.multi
def action_process(self): def action_process(self):
"""Set the account move lines as 'Cleared' and Assign 'Bank Acc Rec Statement ID' """Set the account move lines as 'Cleared' and
Assign 'Bank Acc Rec Statement ID'
for the statement lines which are marked as 'Cleared'.""" for the statement lines which are marked as 'Cleared'."""
# If difference balance not zero prevent further processing # If difference balance not zero prevent further processing
self.check_difference_balance() self.check_difference_balance()
for statement in self: for statement in self:
statement_lines = statement.credit_move_line_ids + statement.debit_move_line_ids statement_lines = statement.credit_move_line_ids + \
statement.debit_move_line_ids
for statement_line in statement_lines: for statement_line in statement_lines:
#Mark the move lines as 'Cleared'mand assign the 'Bank Acc Rec Statement ID' # Mark the move lines as 'Cleared'mand assign
statement_line.move_line_id.write({'cleared_bank_account': statement_line.cleared_bank_account, # the 'Bank Acc Rec Statement ID'
'bank_acc_rec_statement_id': statement_line.cleared_bank_account and statement.id or False statement_id = \
}) statement_line.cleared_bank_account and \
statement.id or False
cleared_bank_account = \
statement_line.cleared_bank_account
statement_line.move_line_id.write({
'cleared_bank_account': cleared_bank_account,
'bank_acc_rec_statement_id': statement_id
})
statement.write({'state': 'done', statement.write({'state': 'done',
'verified_by_user_id': self.env.uid, 'verified_by_user_id': self.env.uid,
'verified_date': time.strftime('%Y-%m-%d') 'verified_date': time.strftime('%Y-%m-%d')
}) })
return True return True
@api.multi @api.multi
def action_cancel_draft(self): def action_cancel_draft(self):
"""Reset the statement to draft and perform resetting operations.""" """Reset the statement to draft and perform resetting operations."""
for statement in self: for statement in self:
statement_lines = statement.credit_move_line_ids + statement.debit_move_line_ids statement_lines = \
statement.credit_move_line_ids + statement.debit_move_line_ids
line_ids = [] line_ids = []
statement_line_ids = [] statement_line_ids = []
for statement_line in statement_lines: for statement_line in statement_lines:
statement_line_ids.append(statement_line) statement_line_ids.append(statement_line)
if statement_line.move_line_id: if statement_line.move_line_id:
line_ids.append(statement_line.move_line_id) # Find move lines related to statement lines # Find move lines related to statement lines
line_ids.append(
statement_line.move_line_id)
# Reset 'Cleared' and 'Bank Acc Rec Statement ID' to False # Reset 'Cleared' and 'Bank Acc Rec Statement ID' to False
line_ids.write({'cleared_bank_account': False, line_ids.write({'cleared_bank_account': False,
'bank_acc_rec_statement_id': False, 'bank_acc_rec_statement_id': False,
}) })
# Reset 'Cleared' in statement lines # Reset 'Cleared' in statement lines
statement_line_ids.write({'cleared_bank_account': False, statement_line_ids.write({'cleared_bank_account': False,
'research_required': False 'research_required': False
}) })
# Reset statement # Reset statement
statement.write({'state': 'draft', statement.write({'state': 'draft',
'verified_by_user_id': False, 'verified_by_user_id': False,
'verified_date': False 'verified_date': False
}) })
return True return True
@api.multi @api.multi
def action_select_all(self): def action_select_all(self):
"""Mark all the statement lines as 'Cleared'.""" """Mark all the statement lines as 'Cleared'."""
for statement in self: for statement in self:
statement_lines = statement.credit_move_line_ids + statement.debit_move_line_ids statement_lines = \
statement.credit_move_line_ids + statement.debit_move_line_ids
statement_line_ids = map(lambda x: x.id, statement_lines) statement_line_ids = map(lambda x: x.id, statement_lines)
statement_line_ids.write({'cleared_bank_account': True}) statement_line_ids.write({'cleared_bank_account': True})
return True return True
@ -150,274 +182,478 @@ class bank_acc_rec_statement(models.Model):
def action_unselect_all(self): def action_unselect_all(self):
"""Reset 'Cleared' in all the statement lines.""" """Reset 'Cleared' in all the statement lines."""
for statement in self: for statement in self:
statement_lines = statement.credit_move_line_ids + statement.debit_move_line_ids statement_lines = \
statement.credit_move_line_ids + statement.debit_move_line_ids
statement_line_ids = map(lambda x: x.id, statement_lines) statement_line_ids = map(lambda x: x.id, statement_lines)
statement_line_ids.write({'cleared_bank_account': False}) statement_line_ids.write({'cleared_bank_account': False})
return True return True
def _get_balance(self): def _get_balance(self):
"""Computed as following: """Computed as following:
A) Deposits, Credits, and Interest Amount: Total SUM of Amts of lines with Cleared = True A) Deposits, Credits, and Interest Amount:
Deposits, Credits, and Interest # of Items: Total of number of lines with Cleared = True Total SUM of Amts of lines with Cleared = True
Deposits, Credits, and Interest # of Items:
Total of number of lines with Cleared = True
B) Checks, Withdrawals, Debits, and Service Charges Amount: B) Checks, Withdrawals, Debits, and Service Charges Amount:
Checks, Withdrawals, Debits, and Service Charges Amount # of Items: Checks, Withdrawals, Debits, and Service Charges Amount # of Items:
Cleared Balance (Total Sum of the Deposit Amount Cleared (A) Total Sum of Checks Amount Cleared (B)) Cleared Balance (Total Sum of the Deposit Amount Cleared (A)
Difference= (Ending Balance Beginning Balance) - cleared balance = should be zero. Total Sum of Checks Amount Cleared (B))
Difference= (Ending Balance Beginning Balance) - cleared balance =
should be zero.
""" """
account_precision = self.env['decimal.precision'].precision_get('Account') account_precision = self.env['decimal.precision'].precision_get(
'Account')
for statement in self: for statement in self:
for line in statement.credit_move_line_ids: for line in statement.credit_move_line_ids:
statement.sum_of_credits += line.cleared_bank_account and float_round(line.amount, account_precision) or 0.0 statement.sum_of_credits += \
statement.sum_of_credits_cur += line.cleared_bank_account and float_round(line.amountcur, account_precision) or 0.0 line.cleared_bank_account and \
statement.sum_of_credits_lines += line.cleared_bank_account and 1.0 or 0.0 float_round(line.amount, account_precision) or 0.0
statement.sum_of_ucredits += (not line.cleared_bank_account) and float_round(line.amount, account_precision) or 0.0 statement.sum_of_credits_cur += \
statement.sum_of_ucredits_cur += (not line.cleared_bank_account) and float_round(line.amountcur, account_precision) or 0.0 line.cleared_bank_account and \
statement.sum_of_ucredits_lines += (not line.cleared_bank_account) and 1.0 or 0.0 float_round(line.amountcur, account_precision) or 0.0
statement.sum_of_credits_lines += \
line.cleared_bank_account and 1.0 or 0.0
statement.sum_of_ucredits += \
(not line.cleared_bank_account) and \
float_round(line.amount, account_precision) or 0.0
statement.sum_of_ucredits_cur += \
(not line.cleared_bank_account) and \
float_round(line.amountcur, account_precision) or 0.0
statement.sum_of_ucredits_lines += \
(not line.cleared_bank_account) and 1.0 or 0.0
for line in statement.debit_move_line_ids: for line in statement.debit_move_line_ids:
statement.sum_of_debits += line.cleared_bank_account and float_round(line.amount, account_precision) or 0.0 statement.sum_of_debits += \
statement.sum_of_debits_cur += line.cleared_bank_account and float_round(line.amountcur, account_precision) or 0.0 line.cleared_bank_account and \
statement.sum_of_debits_lines += line.cleared_bank_account and 1.0 or 0.0 float_round(line.amount, account_precision) or 0.0
statement.sum_of_udebits += (not line.cleared_bank_account) and float_round(line.amount, account_precision) or 0.0 statement.sum_of_debits_cur += \
statement.sum_of_udebits_cur += (not line.cleared_bank_account) and float_round(line.amountcur, account_precision) or 0.0 line.cleared_bank_account and \
statement.sum_of_udebits_lines += (not line.cleared_bank_account) and 1.0 or 0.0 float_round(line.amountcur, account_precision) or 0.0
statement.sum_of_debits_lines += \
line.cleared_bank_account and 1.0 or 0.0
statement.sum_of_udebits += \
(not line.cleared_bank_account) and \
float_round(line.amount, account_precision) or 0.0
statement.sum_of_udebits_cur += \
(not line.cleared_bank_account) and \
float_round(line.amountcur, account_precision) or 0.0
statement.sum_of_udebits_lines += \
(not line.cleared_bank_account) and 1.0 or 0.0
statement.cleared_balance = float_round(
statement.sum_of_debits - statement.sum_of_credits,
account_precision)
statement.cleared_balance_cur = float_round(
statement.sum_of_debits_cur - statement.sum_of_credits_cur,
account_precision)
statement.difference = \
float_round((statement.ending_balance -
statement.starting_balance) -
statement.cleared_balance, account_precision)
statement.difference_cur = \
float_round((statement.ending_balance -
statement.starting_balance) -
statement.cleared_balance_cur, account_precision)
statement.uncleared_balance = float_round(
statement.sum_of_udebits - statement.sum_of_ucredits,
account_precision)
statement.uncleared_balance_cur = float_round(
statement.sum_of_udebits_cur - statement.sum_of_ucredits_cur,
account_precision)
statement.cleared_balance = float_round(statement.sum_of_debits - statement.sum_of_credits, account_precision)
statement.cleared_balance_cur = float_round(statement.sum_of_debits_cur - statement.sum_of_credits_cur, account_precision)
statement.difference = float_round((statement.ending_balance - statement.starting_balance) - statement.cleared_balance, account_precision)
statement.difference_cur = float_round((statement.ending_balance - statement.starting_balance) - statement.cleared_balance_cur, account_precision)
statement.uncleared_balance = float_round(statement.sum_of_udebits - statement.sum_of_ucredits, account_precision)
statement.uncleared_balance_cur = float_round(statement.sum_of_udebits_cur - statement.sum_of_ucredits_cur, account_precision)
# refresh data # refresh data
@api.multi @api.multi
def refresh_record(self): def refresh_record(self):
retval = True retval = True
refdict = {} refdict = {}
# get current state of moves in the statement # get current state of moves in the statement
for statement in self: for statement in self:
if statement.state == 'draft': if statement.state == 'draft':
for cr_item in statement.credit_move_line_ids: for cr_item in statement.credit_move_line_ids:
if cr_item.move_line_id and cr_item.cleared_bank_account: if cr_item.move_line_id and cr_item.cleared_bank_account:
refdict[cr_item.move_line_id.id] = cr_item.cleared_bank_account refdict[cr_item.move_line_id.id] = \
cr_item.cleared_bank_account
for dr_item in statement.debit_move_line_ids: for dr_item in statement.debit_move_line_ids:
if dr_item.move_line_id and dr_item.cleared_bank_account: if dr_item.move_line_id and dr_item.cleared_bank_account:
refdict[dr_item.move_line_id.id] = dr_item.cleared_bank_account refdict[dr_item.move_line_id.id] = \
dr_item.cleared_bank_account
# for the statement # for the statement
for statement in self: for statement in self:
# process only if the statement is in draft state # process only if the statement is in draft state
if statement.state == 'draft': if statement.state == 'draft':
account_id = statement.account_id and statement.account_id.id vals = self.onchange_account_id(
ending_date = statement.ending_date statement.account_id,
suppress_ending_date_filter = statement.suppress_ending_date_filter statement.ending_date,
vals = self.onchange_account_id(statement.account_id, statement.ending_date, statement.suppress_ending_date_filter) statement.suppress_ending_date_filter)
# list of credit lines # list of credit lines
outlist = [] outlist = []
for cr_item in vals['value']['credit_move_line_ids']: for cr_item in vals['value']['credit_move_line_ids']:
cr_item['cleared_bank_account'] = refdict and refdict.get(cr_item['move_line_id'], False) or False cr_item['cleared_bank_account'] = refdict and refdict.get(
cr_item['move_line_id'], False) or False
cr_item['research_required'] = False cr_item['research_required'] = False
item = [0, False, cr_item] item = [0, False, cr_item]
outlist.append(item) outlist.append(item)
# list of debit lines # list of debit lines
inlist = [] inlist = []
for dr_item in vals['value']['debit_move_line_ids']: for dr_item in vals['value']['debit_move_line_ids']:
dr_item['cleared_bank_account'] = refdict and refdict.get(dr_item['move_line_id'], False) or False dr_item['cleared_bank_account'] = refdict and refdict.get(
dr_item['move_line_id'], False) or False
dr_item['research_required'] = False dr_item['research_required'] = False
item = [0, False, dr_item] item = [0, False, dr_item]
inlist.append(item) inlist.append(item)
# write it to the record so it is visible on the form # write it to the record so it is visible on the form
retval = self.write({'last_ending_date':vals['value']['last_ending_date'],'starting_balance': vals['value']['starting_balance'], retval = self.write(
'credit_move_line_ids':outlist, 'debit_move_line_ids': inlist}) {'last_ending_date': vals['value']['last_ending_date'],
'starting_balance': vals['value']['starting_balance'],
'credit_move_line_ids': outlist,
'debit_move_line_ids': inlist})
return retval return retval
# get starting balance for the account # get starting balance for the account
@api.multi @api.multi
def get_starting_balance(self, account_id, ending_date): def get_starting_balance(self, account_id, ending_date):
result = (False,0.0) result = (False, 0.0)
reslist=[] reslist = []
statement_obj = self.env['bank.acc.rec.statement'] statement_obj = self.env['bank.acc.rec.statement']
domain = [('account_id', '=', account_id), ('state', '=', 'done')] domain = [('account_id', '=', account_id), ('state', '=', 'done')]
statement_ids = statement_obj.search(domain).ids statement_ids = statement_obj.search(domain).ids
# get all statements for this account in the past # get all statements for this account in the past
for statement in statement_obj.browse(statement_ids): for statement in statement_obj.browse(statement_ids):
if statement.ending_date < ending_date: if statement.ending_date < ending_date:
reslist.append((statement.ending_date, statement.ending_balance)) reslist.append(
(statement.ending_date, statement.ending_balance))
# get the latest statement value # get the latest statement value
if len(reslist): if len(reslist):
reslist = sorted(reslist,key=itemgetter(0)) reslist = sorted(reslist, key=itemgetter(0))
result = reslist[len(reslist)-1] result = reslist[len(reslist) - 1]
return result return result
@api.onchange('account_id','ending_date','suppress_ending_date_filter') @api.onchange('account_id', 'ending_date', 'suppress_ending_date_filter')
def onchange_account_id(self): def onchange_account_id(self):
account_move_line_obj = self.env['account.move.line'] account_move_line_obj = self.env['account.move.line']
statement_line_obj = self.env['bank.acc.rec.statement.line'] statement_line_obj = self.env['bank.acc.rec.statement.line']
val = {'value': {'credit_move_line_ids': [], 'debit_move_line_ids': []}} val = {
'value': {'credit_move_line_ids': [], 'debit_move_line_ids': []}}
if self.account_id: if self.account_id:
for statement in self: for statement in self:
statement_line_ids = statement_line_obj.search([('statement_id', '=', statement.id)]) statement_line_ids = statement_line_obj.search(
# call unlink method to reset and remove existing statement lines and [('statement_id', '=', statement.id)])
# call unlink method to reset and
# remove existing statement lines and
# mark reset field values in related move lines # mark reset field values in related move lines
statement_line_ids.unlink() statement_line_ids.unlink()
# Apply filter on move lines to allow # Apply filter on move lines to allow
#1. credit and debit side journal items in posted state of the selected GL account # 1. credit and debit side journal items in posted state of
#2. Journal items which are not cleared in previous bank statements # the selected GL account
#3. Date less than or equal to ending date provided the 'Suppress Ending Date Filter' is not checkec # 2. Journal items which are not cleared in
domain = [('account_id', '=', self.account_id.id), ('move_id.state', '=', 'posted'), ('cleared_bank_account', '=', False)] # previous bank statements
# 3. Date less than or equal to ending date provided the
# 'Suppress Ending Date Filter' is not checkec
domain = [('account_id', '=', self.account_id.id),
('move_id.state', '=', 'posted'),
('cleared_bank_account', '=', False)]
if not self.suppress_ending_date_filter: if not self.suppress_ending_date_filter:
domain += [('date', '<=', self.ending_date)] domain += [('date', '<=', self.ending_date)]
line_ids = account_move_line_obj.search(domain).ids line_ids = account_move_line_obj.search(domain).ids
for line in account_move_line_obj.browse(line_ids): for line in account_move_line_obj.browse(line_ids):
amount_currency = (line.amount_currency < 0) and (-1*line.amount_currency) or line.amount_currency amount_currency = (line.amount_currency < 0) and (
-1 * line.amount_currency) or line.amount_currency
res = { res = {
'ref': line.ref, 'ref': line.ref,
'date': line.date, 'date': line.date,
'partner_id': line.partner_id.id, 'partner_id': line.partner_id.id,
'currency_id': line.currency_id.id, 'currency_id': line.currency_id.id,
'amount': line.credit or line.debit, 'amount': line.credit or line.debit,
'amountcur': amount_currency, 'amountcur': amount_currency,
'name': line.name, 'name': line.name,
'move_line_id': line.id, 'move_line_id': line.id,
'type': line.credit and 'cr' or 'dr' 'type': line.credit and 'cr' or 'dr'
} }
if res['type'] == 'cr': if res['type'] == 'cr':
val['value']['credit_move_line_ids'].append(res) val['value']['credit_move_line_ids'].append(res)
else: else:
val['value']['debit_move_line_ids'].append(res) val['value']['debit_move_line_ids'].append(res)
# look for previous statement for the account to pull ending balance as starting balance # look for previous statement for the account to
prev_stmt=self.get_starting_balance(self.account_id.id, self.ending_date) # pull ending balance as starting balance
prev_stmt = self.get_starting_balance(self.account_id.id,
self.ending_date)
val['value']['last_ending_date'] = prev_stmt[0] val['value']['last_ending_date'] = prev_stmt[0]
val['value']['starting_balance'] = prev_stmt[1] val['value']['starting_balance'] = prev_stmt[1]
return val return val
def get_default_company_id(self): def get_default_company_id(self):
return self.env['res.users'].browse([self.env.uid]).company_id.id return self.env['res.users'].browse([self.env.uid]).company_id.id
_name = "bank.acc.rec.statement" _name = "bank.acc.rec.statement"
name = fields.Char('Name', required=True, size=64, states={'done':[('readonly', True)]}, help="This is a unique name identifying the statement (e.g. Bank X January 2012).") name = fields.Char('Name', required=True, size=64,
states={'done': [('readonly', True)]},
help="This is a unique name identifying "
"the statement (e.g. Bank X January 2012).")
account_id = fields.Many2one('account.account', 'Account', required=True, account_id = fields.Many2one('account.account', 'Account', required=True,
states={'done':[('readonly', True)]}, domain="[('company_id', '=', company_id)]", states={'done': [('readonly', True)]},
help="The Bank/Gl Account that is being reconciled.") domain="[('company_id', '=', company_id)]",
ending_date = fields.Date('Ending Date', required=True, states={'done':[('readonly', True)]}, default=time.strftime('%Y-%m-%d'), help="The ending date of your bank statement.") help="The Bank/Gl Account that is being "
last_ending_date = fields.Date('Last Stmt Date', help="The previous statement date of your bank statement.") "reconciled.")
starting_balance = fields.Float('Starting Balance', required=True, digits_compute=dp.get_precision('Account'), help="The Starting Balance on your bank statement.", states={'done':[('readonly', True)]}) ending_date = fields.Date('Ending Date', required=True,
ending_balance = fields.Float('Ending Balance', required=True, digits_compute=dp.get_precision('Account'), help="The Ending Balance on your bank statement.", states={'done':[('readonly', True)]}) states={'done': [('readonly', True)]},
company_id = fields.Many2one('res.company', 'Company', required=True, readonly=True, default=time.strftime('%Y-%m-%d'),
default=get_default_company_id,help="The Company for which the deposit ticket is made to") help="The ending date of your bank statement.")
last_ending_date = fields.Date('Last Stmt Date',
help="The previous statement date "
"of your bank statement.")
starting_balance = fields.Float('Starting Balance', required=True,
digits_compute=dp.get_precision('Account'),
help="The Starting Balance on your "
"bank statement.",
states={'done': [('readonly', True)]})
ending_balance = fields.Float('Ending Balance', required=True,
digits_compute=dp.get_precision('Account'),
help="The Ending Balance on your "
"bank statement.",
states={'done': [('readonly', True)]})
company_id = fields.Many2one('res.company', 'Company', required=True,
readonly=True, default=get_default_company_id,
help="The Company for which the "
"deposit ticket is made to")
notes = fields.Text('Notes') notes = fields.Text('Notes')
verified_date = fields.Date('Verified Date', states={'done':[('readonly', True)]}, verified_date = fields.Date('Verified Date',
help="Date in which Deposit Ticket was verified.") states={'done': [('readonly', True)]},
verified_by_user_id = fields.Many2one('res.users', 'Verified By', states={'done':[('readonly', True)]}, help="Date in which Deposit "
help="Entered automatically by the “last user” who saved it. System generated.") "Ticket was verified.")
credit_move_line_ids = fields.One2many('bank.acc.rec.statement.line', 'statement_id', 'Credits', verified_by_user_id = fields.Many2one('res.users', 'Verified By',
domain=[('type','=','cr')], states={'done':[('readonly', True)]}) states={
debit_move_line_ids = fields.One2many('bank.acc.rec.statement.line', 'statement_id', 'Debits', 'done': [('readonly', True)]},
domain=[('type','=','dr')], states={'done':[('readonly', True)]}) help="Entered automatically by "
cleared_balance = fields.Float(compute='_get_balance', string='Cleared Balance', digits_compute=dp.get_precision('Account'), "the “last user” who saved it. "
help="Total Sum of the Deposit Amount Cleared Total Sum of Checks, Withdrawals, Debits, and Service Charges Amount Cleared") "System generated.")
difference = fields.Float(compute='_get_balance', string='Difference', digits_compute=dp.get_precision('Account'), credit_move_line_ids = fields.One2many('bank.acc.rec.statement.line',
help="(Ending Balance Beginning Balance) - Cleared Balance.") 'statement_id', 'Credits',
cleared_balance_cur = fields.Float(compute='_get_balance', string='Cleared Balance (Cur)', digits_compute=dp.get_precision('Account'), domain=[('type', '=', 'cr')],
help="Total Sum of the Deposit Amount Cleared Total Sum of Checks, Withdrawals, Debits, and Service Charges Amount Cleared") states={
difference_cur = fields.Float(compute='_get_balance', string='Difference (Cur)', digits_compute=dp.get_precision('Account'), 'done': [('readonly', True)]})
help="(Ending Balance Beginning Balance) - Cleared Balance.") debit_move_line_ids = fields.One2many('bank.acc.rec.statement.line',
uncleared_balance = fields.Float(compute='_get_balance', string='Uncleared Balance', digits_compute=dp.get_precision('Account'), 'statement_id', 'Debits',
help="Total Sum of the Deposit Amount Uncleared Total Sum of Checks, Withdrawals, Debits, and Service Charges Amount Uncleared") domain=[('type', '=', 'dr')],
uncleared_balance_cur = fields.Float(compute='_get_balance', string='Unleared Balance (Cur)', digits_compute=dp.get_precision('Account'), states={
help="Total Sum of the Deposit Amount Uncleared Total Sum of Checks, Withdrawals, Debits, and Service Charges Amount Uncleared") 'done': [('readonly', True)]})
sum_of_credits = fields.Float(compute='_get_balance', string='Checks, Withdrawals, Debits, and Service Charges Amount', digits_compute=dp.get_precision('Account'), cleared_balance = fields.Float(compute='_get_balance',
type='float', help="Total SUM of Amts of lines with Cleared = True") string='Cleared Balance',
sum_of_debits = fields.Float(compute='_get_balance', string='Deposits, Credits, and Interest Amount', digits_compute=dp.get_precision('Account'), digits_compute=dp.get_precision('Account'),
help="Total SUM of Amts of lines with Cleared = True") help="Total Sum of the Deposit Amount "
sum_of_credits_cur = fields.Float(compute='_get_balance', string='Checks, Withdrawals, Debits, and Service Charges Amount (Cur)', digits_compute=dp.get_precision('Account'), "Cleared Total Sum of Checks, "
help="Total SUM of Amts of lines with Cleared = True") "Withdrawals, Debits, and Service "
sum_of_debits_cur = fields.Float(compute='_get_balance', string='Deposits, Credits, and Interest Amount (Cur)', digits_compute=dp.get_precision('Account'), "Charges Amount Cleared")
help="Total SUM of Amts of lines with Cleared = True") difference = fields.Float(compute='_get_balance', string='Difference',
sum_of_credits_lines = fields.Float(compute='_get_balance', string='Checks, Withdrawals, Debits, and Service Charges # of Items', digits_compute=dp.get_precision('Account'),
help="Total of number of lines with Cleared = True") help="(Ending Balance Beginning Balance) - "
sum_of_debits_lines = fields.Float(compute='_get_balance', string='Deposits, Credits, and Interest # of Items', "Cleared Balance.")
help="Total of number of lines with Cleared = True") cleared_balance_cur = fields.Float(compute='_get_balance',
sum_of_ucredits = fields.Float(compute='_get_balance', string='Uncleared - Checks, Withdrawals, Debits, and Service Charges Amount', digits_compute=dp.get_precision('Account'), string='Cleared Balance (Cur)',
help="Total SUM of Amts of lines with Cleared = False") digits_compute=dp.get_precision(
sum_of_udebits = fields.Float(compute='_get_balance', string='Uncleared - Deposits, Credits, and Interest Amount', digits_compute=dp.get_precision('Account'), 'Account'),
help="Total SUM of Amts of lines with Cleared = False") help="Total Sum of the Deposit "
sum_of_ucredits_cur = fields.Float(compute='_get_balance', string='Uncleared - Checks, Withdrawals, Debits, and Service Charges Amount (Cur)', digits_compute=dp.get_precision('Account'), "Amount Cleared Total Sum of "
help="Total SUM of Amts of lines with Cleared = False") "Checks, Withdrawals, Debits, and"
sum_of_udebits_cur = fields.Float(compute='_get_balance', string='Uncleared - Deposits, Credits, and Interest Amount (Cur)', digits_compute=dp.get_precision('Account'), " Service Charges Amount Cleared")
help="Total SUM of Amts of lines with Cleared = False") difference_cur = fields.Float(compute='_get_balance',
sum_of_ucredits_lines = fields.Float(compute='_get_balance', string='Uncleared - Checks, Withdrawals, Debits, and Service Charges # of Items', string='Difference (Cur)',
help="Total of number of lines with Cleared = False") digits_compute=dp.get_precision('Account'),
sum_of_udebits_lines = fields.Float(compute='_get_balance', string='Uncleared - Deposits, Credits, and Interest # of Items', help="(Ending Balance Beginning Balance)"
help="Total of number of lines with Cleared = False") " - Cleared Balance.")
suppress_ending_date_filter = fields.Boolean('Remove Ending Date Filter', help="If this is checked then the Statement End Date filter on the transactions below will not occur. All transactions would come over.") uncleared_balance = fields.Float(compute='_get_balance',
string='Uncleared Balance',
digits_compute=dp.get_precision(
'Account'),
help="Total Sum of the Deposit "
"Amount Uncleared Total Sum of "
"Checks, Withdrawals, Debits, and"
" Service Charges Amount Uncleared")
uncleared_balance_cur = fields.Float(compute='_get_balance',
string='Unleared Balance (Cur)',
digits_compute=dp.get_precision(
'Account'),
help="Total Sum of the Deposit Amount"
" Uncleared Total Sum of "
"Checks, Withdrawals, Debits, "
"and Service Charges "
"Amount Uncleared")
sum_of_credits = fields.Float(compute='_get_balance',
string='Checks, Withdrawals, Debits, and'
' Service Charges Amount',
digits_compute=dp.get_precision('Account'),
type='float',
help="Total SUM of Amts of lines with"
" Cleared = True")
sum_of_debits = fields.Float(compute='_get_balance',
string='Deposits, Credits, and '
'Interest Amount',
digits_compute=dp.get_precision('Account'),
help="Total SUM of Amts of lines with "
"Cleared = True")
sum_of_credits_cur = fields.Float(compute='_get_balance',
string='Checks, Withdrawals, Debits, and'
' Service Charges Amount (Cur)',
digits_compute=dp.get_precision(
'Account'),
help="Total SUM of Amts of lines "
"with Cleared = True")
sum_of_debits_cur = fields.Float(compute='_get_balance',
string='Deposits, Credits, and '
'Interest Amount (Cur)',
digits_compute=dp.get_precision(
'Account'),
help="Total SUM of Amts of lines "
"with Cleared = True")
sum_of_credits_lines = fields.Float(compute='_get_balance',
string='Checks, Withdrawals, Debits, '
'and Service Charges # of '
'Items',
help="Total of number of lines with "
"Cleared = True")
sum_of_debits_lines = fields.Float(compute='_get_balance',
string='Deposits, Credits, and Interest'
' # of Items',
help="Total of number of lines with"
" Cleared = True")
sum_of_ucredits = fields.Float(compute='_get_balance',
string='Uncleared - Checks, Withdrawals, '
'Debits, and Service Charges Amount',
digits_compute=dp.get_precision('Account'),
help="Total SUM of Amts of lines with "
"Cleared = False")
sum_of_udebits = fields.Float(compute='_get_balance',
string='Uncleared - Deposits, Credits, '
'and Interest Amount',
digits_compute=dp.get_precision('Account'),
help="Total SUM of Amts of lines with "
"Cleared = False")
sum_of_ucredits_cur = fields.Float(compute='_get_balance',
string='Uncleared - Checks, '
'Withdrawals, Debits, and '
'Service Charges Amount (Cur)',
digits_compute=dp.get_precision(
'Account'),
help="Total SUM of Amts of lines "
"with Cleared = False")
sum_of_udebits_cur = fields.Float(compute='_get_balance',
string='Uncleared - Deposits, Credits, '
'and Interest Amount (Cur)',
digits_compute=dp.get_precision(
'Account'),
help="Total SUM of Amts of lines with"
" Cleared = False")
sum_of_ucredits_lines = fields.Float(compute='_get_balance',
string='Uncleared - Checks, '
'Withdrawals, Debits, and '
'Service Charges # of Items',
help="Total of number of lines with"
" Cleared = False")
sum_of_udebits_lines = fields.Float(compute='_get_balance',
string='Uncleared - Deposits, Credits,'
' and Interest # of Items',
help="Total of number of lines "
"with Cleared = False")
suppress_ending_date_filter = fields.Boolean('Remove Ending Date Filter',
help="If this is checked then"
" the Statement End Date"
" filter on the "
"transactions below will"
" not occur. All "
"transactions would "
"come over.")
state = fields.Selection([ state = fields.Selection([
('draft','Draft'), ('draft', 'Draft'),
('to_be_reviewed','Ready for Review'), ('to_be_reviewed', 'Ready for Review'),
('done','Done'), ('done', 'Done'),
('cancel', 'Cancel') ('cancel', 'Cancel')
],'State', select=True, readonly=True, default='draft') ], 'State', select=True, readonly=True, default='draft')
_order = "ending_date desc" _order = "ending_date desc"
_sql_constraints = [ _sql_constraints = [
('name_company_uniq', 'unique (name, company_id, account_id)', 'The name of the statement must be unique per company and G/L account!') ('name_company_uniq', 'unique (name, company_id, account_id)',
'The name of the statement must be unique per '
'company and G/L account!')
] ]
class bank_acc_rec_statement_line(models.Model): class BankAccRecStatementLine(models.Model):
_name = "bank.acc.rec.statement.line" _name = "bank.acc.rec.statement.line"
_description = "Statement Line" _description = "Statement Line"
name = fields.Char('Name', size=64, help="Derived from the related Journal Item.", required=True) name = fields.Char('Name', size=64,
ref = fields.Char('Reference', size=64, help="Derived from related Journal Item.") help="Derived from the related Journal Item.",
partner_id = fields.Many2one('res.partner', string='Partner', help="Derived from related Journal Item.") required=True)
ref = fields.Char('Reference', size=64,
help="Derived from related Journal Item.")
partner_id = fields.Many2one('res.partner', string='Partner',
help="Derived from related Journal Item.")
amount = fields.Float('Amount', digits_compute=dp.get_precision('Account'), amount = fields.Float('Amount', digits_compute=dp.get_precision('Account'),
help="Derived from the 'debit' amount from related Journal Item.") help="Derived from the 'debit' amount from "
amountcur = fields.Float('Amount in Currency', digits_compute=dp.get_precision('Account'), "related Journal Item.")
help="Derived from the 'amount currency' amount from related Journal Item.") amountcur = fields.Float('Amount in Currency',
date = fields.Date('Date', required=True, help="Derived from related Journal Item.") digits_compute=dp.get_precision('Account'),
statement_id = fields.Many2one('bank.acc.rec.statement', 'Statement', required=True, ondelete='cascade') help="Derived from the 'amount currency' "
move_line_id = fields.Many2one('account.move.line', 'Journal Item', help="Related Journal Item.") "amount from related Journal Item.")
cleared_bank_account = fields.Boolean('Cleared? ', help='Check if the transaction has cleared from the bank') date = fields.Date('Date', required=True,
research_required = fields.Boolean('Research Required? ', help='Check if the transaction should be researched by Accounting personal') help="Derived from related Journal Item.")
currency_id = fields.Many2one('res.currency', 'Currency', help="The optional other currency if it is a multi-currency entry.") statement_id = fields.Many2one('bank.acc.rec.statement', 'Statement',
type = fields.Selection([('dr','Debit'),('cr','Credit')], 'Cr/Dr') required=True, ondelete='cascade')
move_line_id = fields.Many2one('account.move.line', 'Journal Item',
help="Related Journal Item.")
cleared_bank_account = fields.Boolean('Cleared? ',
help='Check if the transaction has '
'cleared from the bank')
research_required = fields.Boolean('Research Required? ',
help='Check if the transaction should '
'be researched by '
'Accounting personal')
currency_id = fields.Many2one('res.currency', 'Currency',
help="The optional other currency if "
"it is a multi-currency entry.")
type = fields.Selection([('dr', 'Debit'), ('cr', 'Credit')], 'Cr/Dr')
@api.model @api.model
def create(self, vals): def create(self, vals):
account_move_line_obj = self.env['account.move.line'] account_move_line_obj = self.env['account.move.line']
# Prevent manually adding new statement line. # Prevent manually adding new statement line.
# This would allow only onchange method to pre-populate statement lines based on the filter rules. # This would allow only onchange method to pre-populate statement lines
# based on the filter rules.
if not vals.get('move_line_id', False): if not vals.get('move_line_id', False):
raise UserError(_("You cannot add any new bank statement line manually as of this revision!")) raise UserError(_(
account_move_line_obj.browse([vals['move_line_id']]).write({'draft_assigned_to_statement': True}) "You cannot add any new bank statement line manually "
return super(bank_acc_rec_statement_line, self).create(vals) "as of this revision!"))
account_move_line_obj.browse([vals['move_line_id']]).write(
{'draft_assigned_to_statement': True})
return super(BankAccRecStatementLine, self).create(vals)
@api.model @api.model
def unlink(self): def unlink(self):
account_move_line_obj = self.env['account.move.line'] account_move_line_obj = self.env['account.move.line']
move_line_ids = [x.move_line_id.id for x in self if x.move_line_id] move_line_ids = [x.move_line_id.id for x in self if x.move_line_id]
#map(lambda x: x.move_line_id.id if x.move_line_id, self.browse(cr, uid, ids, context=context)) # map(lambda x: x.move_line_id.id if x.move_line_id,
# self.browse(cr, uid, ids, context=context))
# Reset field values in move lines to be added later # Reset field values in move lines to be added later
account_move_line_obj.browse(move_line_ids).write({'draft_assigned_to_statement': False, account_move_line_obj.browse(move_line_ids).write(
'cleared_bank_account': False, {'draft_assigned_to_statement': False,
'bank_acc_rec_statement_id': False, 'cleared_bank_account': False,
}) 'bank_acc_rec_statement_id': False,
return super(bank_acc_rec_statement_line, self).unlink() })
return super(BankAccRecStatementLine, self).unlink()

View File

@ -8,8 +8,19 @@ from odoo import fields, models
class AccountMoveLine(models.Model): class AccountMoveLine(models.Model):
_inherit='account.move.line' _inherit = 'account.move.line'
cleared_bank_account = fields.Boolean(string='Cleared? ', help='Check if the transaction has cleared from the bank') cleared_bank_account = fields.Boolean(string='Cleared? ',
bank_acc_rec_statement_id = fields.Many2one('bank.acc.rec.statement', string='Bank Acc Rec Statement', help="The Bank Acc Rec Statement linked with the journal item") help='Check if the transaction '
draft_assigned_to_statement = fields.Boolean(string='Assigned to Statement? ', help='Check if the move line is assigned to statement lines') 'has cleared from the bank')
bank_acc_rec_statement_id = fields.Many2one('bank.acc.rec.statement',
string='Bank Acc Rec '
'Statement',
help="The Bank Acc Rec"
" Statement linked with "
"the journal item")
draft_assigned_to_statement = fields.Boolean(string='Assigned to '
'Statement? ',
help='Check if the move line'
' is assigned to '
'statement lines')

View File

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<!-- QWeb Reports --> <!-- QWeb Reports -->
<report <report
id="bank_statement_detail" id="bank_statement_detail"
model="bank.acc.rec.statement" model="bank.acc.rec.statement"
string="Bank Statement-Detail" string="Bank Statement-Detail"
report_type="qweb-pdf" report_type="qweb-pdf"
name="account_banking_reconciliation.report_bank_statement_detail" name="account_banking_reconciliation.report_bank_statement_detail"
file="account_banking_reconciliation.report_bank_statement_detail" file="account_banking_reconciliation.report_bank_statement_detail"
attachment="'Detail Statement-'+(object.name)+'.pdf'" attachment="'Detail Statement-'+(object.name)+'.pdf'"
/> />
<report <report
id="bank_statement_summary" id="bank_statement_summary"
model="bank.acc.rec.statement" model="bank.acc.rec.statement"
string="Bank Statement-Summary" string="Bank Statement-Summary"
report_type="qweb-pdf" report_type="qweb-pdf"
name="account_banking_reconciliation.report_bank_statement_summary" name="account_banking_reconciliation.report_bank_statement_summary"
file="account_banking_reconciliation.report_bank_statement_summary" file="account_banking_reconciliation.report_bank_statement_summary"
attachment="'Summary Statement-'+(object.name)+'.pdf'" attachment="'Summary Statement-'+(object.name)+'.pdf'"
/> />
</odoo> </odoo>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data>
<template id="report_bank_statement_detail_doc"> <template id="report_bank_statement_detail_doc">
<t t-call="report.external_layout"> <t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.company_id.partner_id.lang})" /> <t t-set="o" t-value="o.with_context({'lang':o.company_id.partner_id.lang})" />
@ -267,5 +266,4 @@
</t> </t>
</t> </t>
</template> </template>
</data>
</odoo> </odoo>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<data>
<template id="report_bank_statement_summary_doc"> <template id="report_bank_statement_summary_doc">
<t t-call="report.external_layout"> <t t-call="report.external_layout">
<t t-set="o" t-value="o.with_context({'lang':o.company_id.partner_id.lang})" /> <t t-set="o" t-value="o.with_context({'lang':o.company_id.partner_id.lang})" />
@ -186,5 +185,4 @@
</t> </t>
</t> </t>
</template> </template>
</data>
</odoo> </odoo>