This commit is contained in:
unknown
2013-04-10 13:25:50 +02:00
parent 8c16725ecb
commit 17f2c78065
2 changed files with 47 additions and 34 deletions

View File

@@ -25,11 +25,9 @@
'maintainer': 'Camptocamp', 'maintainer': 'Camptocamp',
'category': 'Finance', 'category': 'Finance',
'complexity': 'normal', 'complexity': 'normal',
'depends': [ 'depends': ['account',
'account', 'report_webkit',
'report_webkit', 'account_voucher'],
'account_voucher'
],
'description': """ 'description': """
Improve the basic bank statement, by adding various new features, Improve the basic bank statement, by adding various new features,
and help dealing with huge volume of reconciliation through payment offices such as Paypal, Lazer, and help dealing with huge volume of reconciliation through payment offices such as Paypal, Lazer,
@@ -87,4 +85,4 @@
'auto_install': False, 'auto_install': False,
'license': 'AGPL-3', 'license': 'AGPL-3',
'active': False, 'active': False,
} }

View File

@@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp.osv.orm import Model from openerp.osv.orm import Model
from openerp.osv import fields, osv from openerp.osv import fields, osv
from openerp.tools.translate import _ from openerp.tools.translate import _
@@ -44,38 +43,45 @@ class AccountStatementProfil(Model):
"commission move (and optionaly on the counterpart " "commission move (and optionaly on the counterpart "
"of the intermediate/banking move if you tick the " "of the intermediate/banking move if you tick the "
"corresponding checkbox)."), "corresponding checkbox)."),
'journal_id': fields.many2one( 'journal_id': fields.many2one(
'account.journal', 'account.journal',
'Financial journal to use for transaction', 'Financial journal to use for transaction',
required=True), required=True),
'commission_account_id': fields.many2one( 'commission_account_id': fields.many2one(
'account.account', 'account.account',
'Commission account', 'Commission account',
required=True), required=True),
'commission_analytic_id': fields.many2one( 'commission_analytic_id': fields.many2one(
'account.analytic.account', 'account.analytic.account',
'Commission analytic account'), 'Commission analytic account'),
'receivable_account_id': fields.many2one( 'receivable_account_id': fields.many2one(
'account.account', 'account.account',
'Force Receivable/Payable Account', 'Force Receivable/Payable Account',
help="Choose a receivable account to force the default " help="Choose a receivable account to force the default "
"debit/credit account (eg. an intermediat bank account " "debit/credit account (eg. an intermediat bank account "
"instead of default debitors)."), "instead of default debitors)."),
'force_partner_on_bank': fields.boolean( 'force_partner_on_bank': fields.boolean(
'Force partner on bank move', 'Force partner on bank move',
help="Tick that box if you want to use the credit " help="Tick that box if you want to use the credit "
"institute partner in the counterpart of the " "institute partner in the counterpart of the "
"intermediate/banking move."), "intermediate/banking move."),
'balance_check': fields.boolean( 'balance_check': fields.boolean(
'Balance check', 'Balance check',
help="Tick that box if you want OpenERP to control " help="Tick that box if you want OpenERP to control "
"the start/end balance before confirming a bank statement. " "the start/end balance before confirming a bank statement. "
"If don't ticked, no balance control will be done." "If don't ticked, no balance control will be done."),
),
'bank_statement_prefix': fields.char( 'bank_statement_prefix': fields.char('Bank Statement Prefix', size=32),
'Bank Statement Prefix', size=32),
'bank_statement_ids': fields.one2many( 'bank_statement_ids': fields.one2many('account.bank.statement',
'account.bank.statement', 'profile_id', 'Bank Statement Imported'), 'profile_id',
'Bank Statement Imported'),
# TODO # TODO
# 'how_get_type_account': fields.selection( # 'how_get_type_account': fields.selection(
# [ ('amount', 'Based on amount and partner type'), # [ ('amount', 'Based on amount and partner type'),
@@ -186,11 +192,11 @@ class AccountBankSatement(Model):
""" """
for statement in self.browse(cr, uid, ids, context=context): for statement in self.browse(cr, uid, ids, context=context):
if (statement.period_id and if (statement.period_id and
statement.company_id.id != statement.period_id.company_id.id): statement.company_id.id != statement.period_id.company_id.id):
return False return False
for line in statement.line_ids: for line in statement.line_ids:
if (line.period_id and if (line.period_id and
statement.company_id.id != line.period_id.company_id.id): statement.company_id.id != line.period_id.company_id.id):
return False return False
return True return True
@@ -264,8 +270,10 @@ class AccountBankSatement(Model):
create the move from. create the move from.
:return: int/long of the res.partner to use as counterpart :return: int/long of the res.partner to use as counterpart
""" """
bank_partner_id = super(AccountBankSatement, self).\ bank_partner_id = super(AccountBankSatement, self)._get_counter_part_partner(cr,
_get_counter_part_partner(cr, uid, st_line, context=context) uid,
st_line, c
ontext=context)
# get the right partner according to the chosen profil # get the right partner according to the chosen profil
if st_line.statement_id.profile_id.force_partner_on_bank: if st_line.statement_id.profile_id.force_partner_on_bank:
bank_partner_id = st_line.statement_id.profile_id.partner_id.id bank_partner_id = st_line.statement_id.profile_id.partner_id.id
@@ -318,7 +326,7 @@ class AccountBankSatement(Model):
if (not st.journal_id.default_credit_account_id) \ if (not st.journal_id.default_credit_account_id) \
or (not st.journal_id.default_debit_account_id): or (not st.journal_id.default_debit_account_id):
raise osv.except_osv(_('Configuration Error !'), raise osv.except_osv(_('Configuration Error !'),
_('Please verify that an account is defined in the journal.')) _('Please verify that an account is defined in the journal.'))
if not st.name == '/': if not st.name == '/':
st_number = st.name st_number = st.name
@@ -329,7 +337,7 @@ class AccountBankSatement(Model):
for line in st.move_line_ids: for line in st.move_line_ids:
if line.state != 'valid': if line.state != 'valid':
raise osv.except_osv(_('Error !'), raise osv.except_osv(_('Error !'),
_('The account entries lines are not in valid state.')) _('The account entries lines are not in valid state.'))
# begin changes # begin changes
errors_stack = [] errors_stack = []
for st_line in st.line_ids: for st_line in st.line_ids:
@@ -337,11 +345,15 @@ class AccountBankSatement(Model):
if st_line.analytic_account_id: if st_line.analytic_account_id:
if not st.journal_id.analytic_journal_id: if not st.journal_id.analytic_journal_id:
raise osv.except_osv(_('No Analytic Journal !'), raise osv.except_osv(_('No Analytic Journal !'),
_("You have to assign an analytic journal on the '%s' journal!") % (st.journal_id.name,)) _("You have to assign an analytic"
" journal on the '%s' journal!") % (st.journal_id.name,))
if not st_line.amount: if not st_line.amount:
continue continue
st_line_number = self.get_next_st_line_number(cr, uid, st_number, st_line, context) st_line_number = self.get_next_st_line_number(cr, uid, st_number, st_line, context)
self.create_move_from_st_line(cr, uid, st_line.id, company_currency_id, st_line_number, context) self.create_move_from_st_line(cr, uid, st_line.id,
company_currency_id,
st_line_number,
context)
except osv.except_osv, exc: except osv.except_osv, exc:
msg = "Line ID %s with ref %s had following error: %s" % (st_line.id, st_line.ref, exc.value) msg = "Line ID %s with ref %s had following error: %s" % (st_line.id, st_line.ref, exc.value)
errors_stack.append(msg) errors_stack.append(msg)
@@ -352,17 +364,20 @@ class AccountBankSatement(Model):
msg = u"\n".join(errors_stack) msg = u"\n".join(errors_stack)
raise osv.except_osv(_('Error'), msg) raise osv.except_osv(_('Error'), msg)
#end changes #end changes
self.write(cr, uid, [st.id], { self.write(cr, uid, [st.id],
'name': st_number, {'name': st_number,
'balance_end_real': st.balance_end 'balance_end_real': st.balance_end},
}, context=context) context=context)
self.message_post(cr, uid, [st.id], body=_('Statement %s confirmed, journal items were created.') % (st_number,), context=context) self.message_post(cr, uid, [st.id], b
ody=_('Statement %s confirmed, journal items were created.') % (st_number,),
context=context)
return self.write(cr, uid, ids, {'state': 'confirm'}, context=context) return self.write(cr, uid, ids, {'state': 'confirm'}, context=context)
def get_account_for_counterpart(self, cr, uid, amount, account_receivable, account_payable): def get_account_for_counterpart(self, cr, uid, amount, account_receivable, account_payable):
"""For backward compatibility.""" """For backward compatibility."""
account_id, type = self.get_account_and_type_for_counterpart(cr, uid, amount, account_receivable, account_id, type = self.get_account_and_type_for_counterpart(cr, uid, amount,
account_payable) account_receivable,
account_payable)
return account_id return account_id
def get_type_for_counterpart(self, cr, uid, amount, partner_id=False): def get_type_for_counterpart(self, cr, uid, amount, partner_id=False):
@@ -385,12 +400,12 @@ class AccountBankSatement(Model):
type = 'supplier' type = 'supplier'
if partner_id: if partner_id:
part = obj_partner.browse(cr, uid, partner_id, context=context) part = obj_partner.browse(cr, uid, partner_id, context=context)
if part.supplier == True: if part.supplier:
type = 'supplier' type = 'supplier'
elif part.customer == True: elif part.customer:
type = 'customer' type = 'customer'
return type return type
def get_account_and_type_for_counterpart( def get_account_and_type_for_counterpart(
self, cr, uid, amount, account_receivable, account_payable, partner_id=False): self, cr, uid, amount, account_receivable, account_payable, partner_id=False):
""" """
@@ -405,13 +420,13 @@ class AccountBankSatement(Model):
If amount is negativ, the type and account will be supplier and payable If amount is negativ, the type and account will be supplier and payable
Note that we return the payable or receivable account from agrs and not from the optional partner_id Note that we return the payable or receivable account from agrs and not from the optional partner_id
given ! given !
:param float: amount of the line :param float: amount of the line
:param int/long: account_receivable the receivable account :param int/long: account_receivable the receivable account
:param int/long: account_payable the payable account :param int/long: account_payable the payable account
:param int/long: partner_id the partner id :param int/long: partner_id the partner id
:return: dict with [account_id as int/long,type as string]: the default account to be used by :return: dict with [account_id as int/long,type as string]: the default account to be used by
statement line as the counterpart of the journal account depending on the amount and the type statement line as the counterpart of the journal account depending on the amount and the type
as 'customer' or 'supplier'. as 'customer' or 'supplier'.
""" """
account_id = False account_id = False
@@ -592,7 +607,7 @@ class AccountBankSatementLine(Model):
if line_type == 'supplier': if line_type == 'supplier':
account_id = pay_account account_id = pay_account
elif amount is not False: elif amount is not False:
account_id, line_type = obj_stat.get_account_and_type_for_counterpart(cr, uid, amount, account_id, line_type = obj_stat.get_account_and_type_for_counterpart(cr, uid, amount,
receiv_account, pay_account, partner_id=partner_id) receiv_account, pay_account, partner_id=partner_id)
res['account_id'] = account_id if account_id else receiv_account res['account_id'] = account_id if account_id else receiv_account
res['type'] = line_type res['type'] = line_type