[IMP] account_statement_one_move: Fix PEP8

This commit is contained in:
Pedro M. Baeza
2014-08-04 17:50:16 +02:00
parent 5e98a81052
commit d0a06fd532

View File

@@ -20,7 +20,7 @@
# #
############################################################################### ###############################################################################
from openerp.osv import fields, orm, osv from openerp.osv import fields, orm
class AccountStatementProfile(orm.Model): class AccountStatementProfile(orm.Model):
@@ -37,12 +37,12 @@ class AccountStatementProfile(orm.Model):
} }
class account_bank_statement(orm.Model): class AccountBankStatement(orm.Model):
_inherit = "account.bank.statement" _inherit = "account.bank.statement"
def _prepare_move_line_vals(self, cr, uid, st_line, *args, **kwargs): def _prepare_move_line_vals(self, cr, uid, st_line, *args, **kwargs):
res = super(account_bank_statement, self)._prepare_move_line_vals(cr, uid, st_line, res = super(AccountBankStatement, self)._prepare_move_line_vals(
*args, **kwargs) cr, uid, st_line, *args, **kwargs)
period_id = self._get_period(cr, uid, st_line.statement_id.date, period_id = self._get_period(cr, uid, st_line.statement_id.date,
context=kwargs.get('context')) context=kwargs.get('context'))
if st_line.statement_id.profile_id.one_move: if st_line.statement_id.profile_id.one_move:
@@ -56,7 +56,7 @@ class account_bank_statement(orm.Model):
return res return res
def _prepare_move(self, cr, uid, st_line, st_line_number, context=None): def _prepare_move(self, cr, uid, st_line, st_line_number, context=None):
res = super(account_bank_statement, self).\ res = super(AccountBankStatement, self).\
_prepare_move(cr, uid, st_line, st_line_number, context=context) _prepare_move(cr, uid, st_line, st_line_number, context=context)
res.update({ res.update({
'ref': st_line.statement_id.name, 'ref': st_line.statement_id.name,
@@ -71,13 +71,10 @@ class account_bank_statement(orm.Model):
context = {} context = {}
# For compability with module account_constraints # For compability with module account_constraints
context['from_parent_object'] = True context['from_parent_object'] = True
account_move_obj = self.pool.get('account.move') account_move_obj = self.pool['account.move']
account_bank_statement_line_obj = self.pool.get( st_line_obj = self.pool['account.bank.statement.line']
'account.bank.statement.line') st_line = st_line_obj.browse(cr, uid, st_line_id, context=context)
st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id,
context=context)
st = st_line.statement_id st = st_line.statement_id
if st.profile_id.one_move: if st.profile_id.one_move:
if not context.get('move_id'): if not context.get('move_id'):
move_vals = self._prepare_move( move_vals = self._prepare_move(
@@ -89,9 +86,8 @@ class account_bank_statement(orm.Model):
context=context) context=context)
return context['move_id'] return context['move_id']
else: else:
return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line_id, return super(AccountBankStatement, self).create_move_from_st_line(
company_currency_id, cr, uid, st_line_id, company_currency_id, st_line_number,
st_line_number,
context=context) context=context)
def create_move_line_from_st_line(self, cr, uid, move_id, st_line_id, def create_move_line_from_st_line(self, cr, uid, move_id, st_line_id,
@@ -99,48 +95,44 @@ class account_bank_statement(orm.Model):
"""Create the account move line from the statement line. """Create the account move line from the statement line.
:param int/long move_id: ID of the account.move :param int/long move_id: ID of the account.move
:param int/long st_line_id: ID of the account.bank.statement.line to create the move line from. :param int/long st_line_id: ID of the account.bank.statement.line \
:param int/long company_currency_id: ID of the res.currency of the company to create the move line from.
:param int/long company_currency_id: ID of the res.currency of the
company
:return: ID of the account.move created :return: ID of the account.move created
""" """
if context is None: if context is None:
context = {} context = {}
res_currency_obj = self.pool.get('res.currency') res_currency_obj = self.pool['res.currency']
account_move_line_obj = self.pool.get('account.move.line') account_move_line_obj = self.pool['account.move.line']
account_bank_statement_line_obj = self.pool.get( st_line_obj = self.pool['account.bank.statement.line']
'account.bank.statement.line') st_line = st_line_obj.browse(cr, uid, st_line_id, context=context)
st_line = account_bank_statement_line_obj.browse(
cr, uid, st_line_id, context=context)
st = st_line.statement_id st = st_line.statement_id
context.update({'date': st_line.date}) context.update({'date': st_line.date})
acc_cur = ((st_line.amount <= 0) acc_cur = (((st_line.amount <= 0)
and st.journal_id.default_debit_account_id) or st_line.account_id and st.journal_id.default_debit_account_id) or
st_line.account_id)
context.update({ context.update({
'res.currency.compute.account': acc_cur, 'res.currency.compute.account': acc_cur,
}) })
amount = res_currency_obj.compute(cr, uid, st.currency.id, amount = res_currency_obj.compute(
company_currency_id, cr, uid, st.currency.id, company_currency_id, st_line.amount,
st_line.amount, context=context)
bank_move_vals = self._prepare_bank_move_line(
cr, uid, st_line, move_id, amount, company_currency_id,
context=context)
return account_move_line_obj.create(cr, uid, bank_move_vals,
context=context) context=context)
bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount,
company_currency_id, context=context)
return account_move_line_obj.create(cr, uid, bank_move_vals, context=context)
def _valid_move(self, cr, uid, move_id, context=None): def _valid_move(self, cr, uid, move_id, context=None):
move_obj = self.pool.get('account.move') move_obj = self.pool['account.move']
move = move_obj.browse(cr, uid, move_id, context=context)
move_obj.post(cr, uid, [move_id], context=context) move_obj.post(cr, uid, [move_id], context=context)
return True return True
def _prepare_transfer_move_line_vals(self, cr, uid, st, name, amount, move_id, context=None): def _prepare_transfer_move_line_vals(self, cr, uid, st, name, amount,
""" move_id, context=None):
Prepare the dict of values to create the transfer move lines. """Prepare the dict of values to create the transfer move lines."""
"""
account_id = st.profile_id.journal_id.default_debit_account_id.id account_id = st.profile_id.journal_id.default_debit_account_id.id
partner_id = st.profile_id.partner_id and profile.partner_id.id or False
if amount < 0.0: if amount < 0.0:
debit = 0.0 debit = 0.0
credit = -amount credit = -amount
@@ -150,7 +142,7 @@ class account_bank_statement(orm.Model):
vals = { vals = {
'name': name, 'name': name,
'date': st.date, 'date': st.date,
'partner_id': partner_id, 'partner_id': st.profile_id.partner_id.id,
'statement_id': st.id, 'statement_id': st.id,
'account_id': account_id, 'account_id': account_id,
'ref': name, 'ref': name,
@@ -163,7 +155,7 @@ class account_bank_statement(orm.Model):
return vals return vals
def create_move_transfer_lines(self, cr, uid, move, st, context=None): def create_move_transfer_lines(self, cr, uid, move, st, context=None):
move_line_obj = self.pool.get('account.move.line') move_line_obj = self.pool['account.move.line']
move_id = move.id move_id = move.id
refund = 0.0 refund = 0.0
payment = 0.0 payment = 0.0
@@ -184,28 +176,22 @@ class account_bank_statement(orm.Model):
if amount: if amount:
transfer_lines.append(['Transfer', amount]) transfer_lines.append(['Transfer', amount])
for transfer_line in transfer_lines: for transfer_line in transfer_lines:
vals = self._prepare_transfer_move_line_vals(cr, uid, st, vals = self._prepare_transfer_move_line_vals(
transfer_line[0], cr, uid, st, transfer_line[0], transfer_line[1], move_id,
transfer_line[1],
move_id,
context=context) context=context)
transfer_line_ids.append( transfer_line_ids.append(
move_line_obj.create(cr, uid, vals, context=context)) move_line_obj.create(cr, uid, vals, context=context))
return transfer_line_ids return transfer_line_ids
def button_confirm_bank(self, cr, uid, ids, context=None): def button_confirm_bank(self, cr, uid, ids, context=None):
st_line_obj = self.pool.get('account.bank.statement.line') st_line_obj = self.pool['account.bank.statement.line']
move_obj = self.pool.get('account.move')
if context is None: if context is None:
context = {} context = {}
for st in self.browse(cr, uid, ids, context=context): for st in self.browse(cr, uid, ids, context=context):
super(account_bank_statement, self).button_confirm_bank(cr, uid, ids, super(AccountBankStatement, self).button_confirm_bank(
context=context) cr, uid, ids, context=context)
if st.profile_id.one_move and context.get('move_id', False): if st.profile_id.one_move and context.get('move_id', False):
move_id = context['move_id'] move_id = context['move_id']
move = move_obj.browse(cr, uid, move_id, context=context)
transfe_line_ids = self.create_move_transfer_lines(
cr, uid, move, st, context=context)
self._valid_move(cr, uid, move_id, context=context) self._valid_move(cr, uid, move_id, context=context)
lines_ids = [x.id for x in st.line_ids] lines_ids = [x.id for x in st.line_ids]
st_line_obj.write(cr, uid, lines_ids, st_line_obj.write(cr, uid, lines_ids,
@@ -214,7 +200,6 @@ class account_bank_statement(orm.Model):
return True return True
def button_cancel(self, cr, uid, ids, context=None): def button_cancel(self, cr, uid, ids, context=None):
done = []
for st in self.browse(cr, uid, ids, context=context): for st in self.browse(cr, uid, ids, context=context):
if st.profile_id.one_move and st.line_ids: if st.profile_id.one_move and st.line_ids:
for move in st.line_ids[0].move_ids: for move in st.line_ids[0].move_ids:
@@ -223,6 +208,6 @@ class account_bank_statement(orm.Model):
move.unlink(context=context) move.unlink(context=context)
st.write({'state': 'draft'}, context=context) st.write({'state': 'draft'}, context=context)
else: else:
super(account_bank_statement, self).button_cancel(cr, uid, ids, super(AccountBankStatement, self).button_cancel(
context=context) cr, uid, ids, context=context)
return True return True