mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] pep8, pylint, eyeballing
This commit is contained in:
@@ -19,11 +19,10 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields, osv, osv
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class AccountStatementProfil(Model):
|
||||
"""
|
||||
@@ -33,45 +32,53 @@ class AccountStatementProfil(Model):
|
||||
"""
|
||||
_name = "account.statement.profile"
|
||||
_description = "Statement Profil"
|
||||
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, required=True),
|
||||
'partner_id': fields.many2one('res.partner',
|
||||
'Bank/Payment Office partner',
|
||||
help="Put a partner if you want to have it on the commission move \
|
||||
(and optionaly on the counterpart of the intermediate/banking move \
|
||||
if you tic the corresponding checkbox)."),
|
||||
'journal_id': fields.many2one('account.journal',
|
||||
'Financial journal to use for transaction',
|
||||
required=True),
|
||||
'commission_account_id': fields.many2one('account.account',
|
||||
'Commission account',
|
||||
required=True),
|
||||
'commission_analytic_id': fields.many2one('account.analytic.account',
|
||||
'Commission analytic account'),
|
||||
'receivable_account_id': fields.many2one('account.account',
|
||||
'Force Receivable/Payable Account',
|
||||
help="Choose a receivable account to force the default\
|
||||
debit/credit account (eg. an intermediat bank account instead of\
|
||||
default debitors)."),
|
||||
'force_partner_on_bank': fields.boolean('Force partner on bank move',
|
||||
help="Tic that box if you want to use the credit insitute partner\
|
||||
in the counterpart of the intermediat/banking move."
|
||||
),
|
||||
'balance_check': fields.boolean('Balance check',
|
||||
help="Tic that box if you want OpenERP to control the start/end \
|
||||
balance before confirming a bank statement. If don't ticked, no \
|
||||
balance control will be done."
|
||||
),
|
||||
'bank_statement_prefix': fields.char('Bank Statement Prefix', size=32),
|
||||
'bank_statement_ids': fields.one2many('account.bank.statement', 'profile_id', 'Bank Statement Imported'),
|
||||
|
||||
|
||||
'name': fields.char('Name', required=True),
|
||||
'partner_id': fields.many2one(
|
||||
'res.partner',
|
||||
'Bank/Payment Office partner',
|
||||
help="Put a partner if you want to have it on the "
|
||||
"commission move (and optionaly on the counterpart "
|
||||
"of the intermediate/banking move if you tick the "
|
||||
"corresponding checkbox)."),
|
||||
'journal_id': fields.many2one(
|
||||
'account.journal',
|
||||
'Financial journal to use for transaction',
|
||||
required=True),
|
||||
'commission_account_id': fields.many2one(
|
||||
'account.account',
|
||||
'Commission account',
|
||||
required=True),
|
||||
'commission_analytic_id': fields.many2one(
|
||||
'account.analytic.account',
|
||||
'Commission analytic account'),
|
||||
'receivable_account_id': fields.many2one(
|
||||
'account.account',
|
||||
'Force Receivable/Payable Account',
|
||||
help="Choose a receivable account to force the default "
|
||||
"debit/credit account (eg. an intermediat bank account "
|
||||
"instead of default debitors)."),
|
||||
'force_partner_on_bank': fields.boolean(
|
||||
'Force partner on bank move',
|
||||
help="Tick that box if you want to use the credit "
|
||||
"institute partner in the counterpart of the "
|
||||
"intermediate/banking move."),
|
||||
'balance_check': fields.boolean(
|
||||
'Balance check',
|
||||
help="Tick that box if you want OpenERP to control "
|
||||
"the start/end balance before confirming a bank statement. "
|
||||
"If don't ticked, no balance control will be done."
|
||||
),
|
||||
'bank_statement_prefix': fields.char(
|
||||
'Bank Statement Prefix', size=32),
|
||||
'bank_statement_ids': fields.one2many(
|
||||
'account.bank.statement', 'profile_id', 'Bank Statement Imported'),
|
||||
}
|
||||
|
||||
|
||||
def _check_partner(self, cr, uid, ids, context=None):
|
||||
obj = self.browse(cr, uid, ids[0], context=context)
|
||||
if obj.partner_id == False and obj.force_partner_on_bank:
|
||||
if obj.partner_id is False and obj.force_partner_on_bank:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -82,57 +89,65 @@ class AccountStatementProfil(Model):
|
||||
|
||||
class AccountBankSatement(Model):
|
||||
"""
|
||||
We improve the bank statement class mostly for :
|
||||
- Removing the period and compute it from the date of each line.
|
||||
We improve the bank statement class mostly for :
|
||||
- Removing the period and compute it from the date of each line.
|
||||
- Allow to remove the balance check depending on the chosen profile
|
||||
- Report errors on confirmation all at once instead of crashing onr by one
|
||||
- Add a profile notion that can change the generated entries on statement
|
||||
- Add a profile notion that can change the generated entries on statement
|
||||
confirmation.
|
||||
For this, we had to override quite some long method and we'll need to maintain
|
||||
them up to date. Changes are point up by '#Chg' comment.
|
||||
"""
|
||||
|
||||
_inherit = "account.bank.statement"
|
||||
|
||||
|
||||
_columns = {
|
||||
'profile_id': fields.many2one('account.statement.profile',
|
||||
'Profil', required=True, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'profile_id': fields.many2one(
|
||||
'account.statement.profile',
|
||||
'Profil',
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={'draft': [('readonly', False)]}),
|
||||
'credit_partner_id': fields.related(
|
||||
'profile_id',
|
||||
'partner_id',
|
||||
type='many2one',
|
||||
relation='res.partner',
|
||||
string='Financial Partner',
|
||||
store=True, readonly=True),
|
||||
'balance_check': fields.related(
|
||||
'profile_id',
|
||||
'balance_check',
|
||||
type='boolean',
|
||||
string='Balance check',
|
||||
store=True, readonly=True),
|
||||
'journal_id': fields.related(
|
||||
'profile_id',
|
||||
'journal_id',
|
||||
'profile_id',
|
||||
'partner_id',
|
||||
type='many2one',
|
||||
relation='account.journal',
|
||||
string='Journal',
|
||||
store=True, readonly=True),
|
||||
'period_id': fields.many2one('account.period', 'Period', required=False, readonly=True),
|
||||
relation='res.partner',
|
||||
string='Financial Partner',
|
||||
store=True,
|
||||
readonly=True),
|
||||
'balance_check': fields.related(
|
||||
'profile_id',
|
||||
'balance_check',
|
||||
type='boolean',
|
||||
string='Balance check',
|
||||
store=True,
|
||||
readonly=True),
|
||||
'journal_id': fields.related(
|
||||
'profile_id',
|
||||
'journal_id',
|
||||
type='many2one',
|
||||
relation='account.journal',
|
||||
string='Journal',
|
||||
store=True,
|
||||
readonly=True),
|
||||
'period_id': fields.many2one(
|
||||
'account.period', 'Period', required=False, readonly=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'period_id': lambda *a: False,
|
||||
'period_id': False,
|
||||
}
|
||||
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
"""Need to pass the journal_id in vals anytime because of account.cash.statement
|
||||
need it."""
|
||||
if 'profile_id' in vals:
|
||||
profile_obj = self.pool.get('account.statement.profile')
|
||||
profile = profile_obj.browse(cr,uid,vals['profile_id'],context)
|
||||
profile = profile_obj.browse(cr, uid, vals['profile_id'], context=context)
|
||||
vals['journal_id'] = profile.journal_id.id
|
||||
return super(AccountBankSatement, self).create(cr, uid, vals, context=context)
|
||||
|
||||
|
||||
def _get_period(self, cursor, uid, date, context=None):
|
||||
"""
|
||||
Find matching period for date, used in the statement line creation.
|
||||
@@ -140,7 +155,7 @@ class AccountBankSatement(Model):
|
||||
period_obj = self.pool.get('account.period')
|
||||
periods = period_obj.find(cursor, uid, dt=date, context=context)
|
||||
return periods and periods[0] or False
|
||||
|
||||
|
||||
def _check_company_id(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Adapt this constraint method from the account module to reflect the
|
||||
@@ -157,25 +172,27 @@ class AccountBankSatement(Model):
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(_check_company_id, 'The journal and period chosen have to belong to the same company.', ['journal_id','period_id']),
|
||||
(_check_company_id,
|
||||
'The journal and period chosen have to belong to the same company.',
|
||||
['journal_id', 'period_id']),
|
||||
]
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context={}):
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
We cancel the related move, delete them and finally put the
|
||||
statement in draft state. So no need to unreconcile all entries,
|
||||
then unpost them, then finaly cancel the bank statement.
|
||||
"""
|
||||
done = []
|
||||
for st in self.browse(cr, uid, ids, context=context):
|
||||
if st.state=='draft':
|
||||
if st.state == 'draft':
|
||||
continue
|
||||
ids = []
|
||||
for line in st.line_ids:
|
||||
for move in line.move_ids:
|
||||
if move.state <> 'draft':
|
||||
if move.state != 'draft':
|
||||
move.button_cancel(context=context)
|
||||
return super(AccountBankSatement, self).button_cancel(cr, uid, vals, context=context)
|
||||
return super(AccountBankSatement, self).button_cancel(
|
||||
cr, uid, ids, context=context)
|
||||
|
||||
def _prepare_move(self, cr, uid, st_line, st_line_number, context=None):
|
||||
"""Add the period_id from the statement line date to the move preparation.
|
||||
@@ -187,19 +204,21 @@ class AccountBankSatement(Model):
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(AccountBankSatement, self)._prepare_move(cr, uid, st_line, st_line_number, context=context)
|
||||
res = super(AccountBankSatement, self)._prepare_move(
|
||||
cr, uid, st_line, st_line_number, context=context)
|
||||
ctx = context.copy()
|
||||
ctx['company_id'] = st_line.company_id.id
|
||||
period_id = self._get_period(cr, uid, st_line.date, context=ctx)
|
||||
res.update({'period_id': period_id})
|
||||
return res
|
||||
|
||||
def _prepare_move_line_vals(self, cr, uid, st_line, move_id, debit, credit, currency_id = False,
|
||||
amount_currency= False, account_id = False, analytic_id = False,
|
||||
partner_id = False, context=None):
|
||||
def _prepare_move_line_vals(
|
||||
self, cr, uid, st_line, move_id, debit, credit, currency_id=False,
|
||||
amount_currency=False, account_id=False, analytic_id=False,
|
||||
partner_id=False, context=None):
|
||||
"""Add the period_id from the statement line date to the move preparation.
|
||||
Originaly, it was taken from the statement period_id
|
||||
|
||||
|
||||
:param browse_record st_line: account.bank.statement.line record to
|
||||
create the move from.
|
||||
:param int/long move_id: ID of the account.move to link the move line
|
||||
@@ -215,9 +234,13 @@ class AccountBankSatement(Model):
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(AccountBankSatement, self)._prepare_move_line_vals(cr, uid, st_line, move_id, debit,
|
||||
credit, currency_id = currency_id, amount_currency = amount_currency, account_id = account_id,
|
||||
analytic_id = analytic_id, partner_id = partner_id, context = context)
|
||||
res = super(AccountBankSatement, self)._prepare_move_line_vals(
|
||||
cr, uid, st_line, move_id, debit, credit,
|
||||
currency_id=currency_id,
|
||||
amount_currency=amount_currency,
|
||||
account_id=account_id,
|
||||
analytic_id=analytic_id,
|
||||
partner_id=partner_id, context=context)
|
||||
ctx = context.copy()
|
||||
ctx['company_id'] = st_line.company_id.id
|
||||
period_id = self._get_period(cr, uid, st_line.date, context=ctx)
|
||||
@@ -235,28 +258,31 @@ class AccountBankSatement(Model):
|
||||
create the move from.
|
||||
:return: int/long of the res.partner to use as counterpart
|
||||
"""
|
||||
bank_partner_id = super(AccountBankSatement, self)._get_counter_part_partner(cr, uid, st_line, context=context)
|
||||
# GET THE RIGHT PARTNER ACCORDING TO THE CHOSEN PROFIL
|
||||
bank_partner_id = super(AccountBankSatement, self).\
|
||||
_get_counter_part_partner(cr, uid, st_line, context=context)
|
||||
# get the right partner according to the chosen profil
|
||||
if st_line.statement_id.profile_id.force_partner_on_bank:
|
||||
bank_partner_id = st_line.statement_id.profile_id.partner_id.id
|
||||
return bank_partner_id
|
||||
|
||||
def _get_st_number_period_profile(self, cr, uid, date, profile_id):
|
||||
"""
|
||||
Retrieve the name of bank statement from sequence, according to the period
|
||||
Retrieve the name of bank statement from sequence, according to the period
|
||||
corresponding to the date passed in args. Add a prefix if set in the profile.
|
||||
|
||||
|
||||
:param: date: date of the statement used to compute the right period
|
||||
:param: int/long: profile_id: the account.statement.profile ID from which to take the
|
||||
bank_statement_prefix for the name
|
||||
:return: char: name of the bank statement (st_number)
|
||||
|
||||
|
||||
"""
|
||||
year = self.pool.get('account.period').browse(cr, uid, self._get_period(cr, uid, date)).fiscalyear_id.id
|
||||
profile = self.pool.get('account.statement.profile').browse(cr,uid, profile_id)
|
||||
year = self.pool.get('account.period').browse(
|
||||
cr, uid, self._get_period(cr, uid, date)).fiscalyear_id.id
|
||||
profile = self.pool.get('account.statement.profile').browse(cr, uid, profile_id)
|
||||
c = {'fiscalyear_id': year}
|
||||
obj_seq = self.pool.get('ir.sequence')
|
||||
journal_sequence_id = profile.journal_id.sequence_id and profile.journal_id.sequence_id.id or False
|
||||
journal_sequence_id = (profile.journal_id.sequence_id and
|
||||
profile.journal_id.sequence_id.id or False)
|
||||
if journal_sequence_id:
|
||||
st_number = obj_seq.next_by_id(cr, uid, journal_sequence_id, context=c)
|
||||
else:
|
||||
@@ -272,19 +298,16 @@ class AccountBankSatement(Model):
|
||||
instead of having them pop one by one.
|
||||
We have to copy paste a big block of code, changing the error
|
||||
stack + managing period from date.
|
||||
|
||||
|
||||
TODO: Log the error in a bank statement field instead of using a popup !
|
||||
"""
|
||||
# obj_seq = self.pool.get('irerrors_stack.sequence')
|
||||
if context is None:
|
||||
context = {}
|
||||
for st in self.browse(cr, uid, ids, context=context):
|
||||
|
||||
j_type = st.journal_id.type
|
||||
company_currency_id = st.journal_id.company_id.currency_id.id
|
||||
if not self.check_status_condition(cr, uid, st.state, journal_type=j_type):
|
||||
continue
|
||||
|
||||
|
||||
self.balance_check(cr, uid, st.id, journal_type=j_type, context=context)
|
||||
if (not st.journal_id.default_credit_account_id) \
|
||||
or (not st.journal_id.default_debit_account_id):
|
||||
@@ -294,11 +317,11 @@ class AccountBankSatement(Model):
|
||||
if not st.name == '/':
|
||||
st_number = st.name
|
||||
else:
|
||||
# Begin Changes
|
||||
# Begin Changes
|
||||
st_number = self._get_st_number_period_profile(cr, uid, st.date, st.profile_id.id)
|
||||
# End Changes
|
||||
# End Changes
|
||||
for line in st.move_line_ids:
|
||||
if line.state <> 'valid':
|
||||
if line.state != 'valid':
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('The account entries lines are not in valid state.'))
|
||||
# begin changes
|
||||
@@ -328,18 +351,18 @@ class AccountBankSatement(Model):
|
||||
'balance_end_real': st.balance_end
|
||||
}, context=context)
|
||||
self.message_post(cr, uid, [st.id], body=_('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, cursor, uid,
|
||||
amount, account_receivable, account_payable):
|
||||
def get_account_for_counterpart(
|
||||
self, cursor, uid, amount, account_receivable, account_payable):
|
||||
"""
|
||||
Give the amount, payable and receivable account (that can be found using
|
||||
get_default_pay_receiv_accounts method) and receive the one to use. This method
|
||||
should be use when there is no other way to know which one to take.
|
||||
|
||||
|
||||
:param float: amount of the line
|
||||
:param int/long: account_receivable the receivable account
|
||||
:param int/long: account_payable the payable account
|
||||
:param int/long: account_receivable the receivable account
|
||||
:param int/long: account_payable the payable account
|
||||
:return: int/long :the default account to be used by statement line as the counterpart
|
||||
of the journal account depending on the amount.
|
||||
"""
|
||||
@@ -358,16 +381,15 @@ class AccountBankSatement(Model):
|
||||
def get_default_pay_receiv_accounts(self, cursor, uid, context=None):
|
||||
"""
|
||||
We try to determine default payable/receivable accounts to be used as counterpart
|
||||
from the company default propoerty. This is to be used if there is no otherway to
|
||||
find the good one, or to find a default value that will be overriden by a completion
|
||||
from the company default propoerty. This is to be used if there is no otherway to
|
||||
find the good one, or to find a default value that will be overriden by a completion
|
||||
method (rules of account_statement_base_completion) afterwards.
|
||||
|
||||
|
||||
:return: tuple of int/long ID that give account_receivable, account_payable based on
|
||||
company default.
|
||||
"""
|
||||
account_receivable = False
|
||||
account_payable = False
|
||||
context = context or {}
|
||||
property_obj = self.pool.get('ir.property')
|
||||
model_fields_obj = self.pool.get('ir.model.fields')
|
||||
model_fields_ids = model_fields_obj.search(
|
||||
@@ -375,20 +397,20 @@ class AccountBankSatement(Model):
|
||||
uid,
|
||||
[('name', 'in', ['property_account_receivable',
|
||||
'property_account_payable']),
|
||||
('model', '=', 'res.partner'),],
|
||||
('model', '=', 'res.partner')],
|
||||
context=context
|
||||
)
|
||||
property_ids = property_obj.search(
|
||||
cursor,
|
||||
uid, [
|
||||
('fields_id', 'in', model_fields_ids),
|
||||
('res_id', '=', False),
|
||||
],
|
||||
uid,
|
||||
[('fields_id', 'in', model_fields_ids),
|
||||
('res_id', '=', False),
|
||||
],
|
||||
context=context
|
||||
)
|
||||
|
||||
for erp_property in property_obj.browse(cursor, uid,
|
||||
property_ids, context=context):
|
||||
|
||||
for erp_property in property_obj.browse(
|
||||
cursor, uid, property_ids, context=context):
|
||||
if erp_property.fields_id.name == 'property_account_receivable':
|
||||
account_receivable = erp_property.value_reference.id
|
||||
elif erp_property.fields_id.name == 'property_account_payable':
|
||||
@@ -399,41 +421,46 @@ class AccountBankSatement(Model):
|
||||
"""
|
||||
Balance check depends on the profile. If no check for this profile is required,
|
||||
return True and do nothing, otherwise call super.
|
||||
|
||||
:param int/long st_id: ID of the concerned account.bank.statement
|
||||
|
||||
:param int/long st_id: ID of the concerned account.bank.statement
|
||||
:param char: journal_type that concern the bank statement
|
||||
:return: True
|
||||
"""
|
||||
st = self.browse(cr, uid, st_id, context=context)
|
||||
if st.balance_check:
|
||||
return super(AccountBankSatement,self).balance_check(cr, uid, st_id, journal_type, context)
|
||||
return super(AccountBankSatement, self).balance_check(
|
||||
cr, uid, st_id, journal_type, context=context)
|
||||
else:
|
||||
return True
|
||||
|
||||
def onchange_imp_config_id(self, cr, uid, ids, profile_id, context=None):
|
||||
"""
|
||||
Compute values on the change of the profile.
|
||||
|
||||
|
||||
:param: int/long: profile_id that changed
|
||||
:return dict of dict with key = name of the field
|
||||
"""
|
||||
if not profile_id:
|
||||
return {}
|
||||
import_config = self.pool.get("account.statement.profile").browse(cr,uid,profile_id)
|
||||
import_config = self.pool.get("account.statement.profile").browse(
|
||||
cr, uid, profile_id, context=context)
|
||||
journal_id = import_config.journal_id.id
|
||||
account_id = import_config.journal_id.default_debit_account_id.id
|
||||
credit_partner_id = import_config.partner_id and import_config.partner_id.id or False
|
||||
return {'value': {'journal_id':journal_id, 'account_id': account_id,
|
||||
'balance_check':import_config.balance_check,
|
||||
'credit_partner_id':credit_partner_id,
|
||||
}}
|
||||
return {'value':
|
||||
{'journal_id': journal_id,
|
||||
'account_id': account_id,
|
||||
'balance_check': import_config.balance_check,
|
||||
'credit_partner_id': credit_partner_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AccountBankSatementLine(Model):
|
||||
"""
|
||||
Override to compute the period from the date of the line, add a method to retrieve
|
||||
the values for a line from the profile. Override the on_change method to take care of
|
||||
the profile when fullfilling the bank statement manually. Set the reference to 64
|
||||
the values for a line from the profile. Override the on_change method to take care of
|
||||
the profile when fullfilling the bank statement manually. Set the reference to 64
|
||||
Char long instead 32.
|
||||
"""
|
||||
_inherit = "account.bank.statement.line"
|
||||
@@ -447,8 +474,8 @@ class AccountBankSatementLine(Model):
|
||||
return periods and periods[0] or False
|
||||
|
||||
def _get_default_account(self, cursor, user, context=None):
|
||||
return self.get_values_for_line(cursor, user, context = context)['account_id']
|
||||
|
||||
return self.get_values_for_line(cursor, user, context=context)['account_id']
|
||||
|
||||
_columns = {
|
||||
# Set them as required + 64 char instead of 32
|
||||
'ref': fields.char('Reference', size=64, required=True),
|
||||
@@ -458,8 +485,8 @@ class AccountBankSatementLine(Model):
|
||||
'period_id': _get_period,
|
||||
'account_id': _get_default_account,
|
||||
}
|
||||
|
||||
def get_values_for_line(self, cr, uid, profile_id = False, partner_id = False, line_type = False, amount = False, context = None):
|
||||
|
||||
def get_values_for_line(self, cr, uid, profile_id=False, partner_id=False, line_type=False, amount=False, context=None):
|
||||
"""
|
||||
Return the account_id to be used in the line of a bank statement. It'll base the result as follow:
|
||||
- If a receivable_account_id is set in the profile, return this value and type = general
|
||||
@@ -470,7 +497,7 @@ class AccountBankSatementLine(Model):
|
||||
so it is easier for the accountant to know why the receivable/payable has been chosen
|
||||
- Then, if no partner are given we look and take the property from the company so we always give a value
|
||||
for account_id. Note that in that case, we return the receivable one.
|
||||
|
||||
|
||||
:param int/long profile_id of the related bank statement
|
||||
:param int/long partner_id of the line
|
||||
:param char line_type: a value from: 'general', 'supplier', 'customer'
|
||||
@@ -483,17 +510,16 @@ class AccountBankSatementLine(Model):
|
||||
...
|
||||
}
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
obj_partner = self.pool.get('res.partner')
|
||||
obj_stat = self.pool.get('account.bank.statement')
|
||||
receiv_account = pay_account = account_id = False
|
||||
# If profile has a receivable_account_id, we return it in any case
|
||||
if profile_id:
|
||||
profile = self.pool.get("account.statement.profile").browse(cr,uid,profile_id)
|
||||
profile = self.pool.get("account.statement.profile").browse(
|
||||
cr, uid, profile_id, context=context)
|
||||
if profile.receivable_account_id:
|
||||
res['account_id'] = profile.receivable_account_id.id
|
||||
res['account_id'] = profile.receivable_account_id.id
|
||||
res['type'] = 'general'
|
||||
return res
|
||||
# If partner -> take from him
|
||||
@@ -503,7 +529,8 @@ class AccountBankSatementLine(Model):
|
||||
receiv_account = part.property_account_receivable.id
|
||||
# If no value, look on the default company property
|
||||
if not pay_account or not receiv_account:
|
||||
receiv_account, pay_account = obj_stat.get_default_pay_receiv_accounts(cr, uid, context=None)
|
||||
receiv_account, pay_account = obj_stat.get_default_pay_receiv_accounts(
|
||||
cr, uid, context=None)
|
||||
# Now we have both pay and receive account, choose the one to use
|
||||
# based on line_type first, then amount, otherwise take receivable one.
|
||||
if line_type is not False:
|
||||
@@ -519,18 +546,15 @@ class AccountBankSatementLine(Model):
|
||||
res['account_id'] = pay_account
|
||||
res['type'] = 'supplier'
|
||||
if not account_id:
|
||||
res['account_id'] = receiv_account
|
||||
res['account_id'] = receiv_account
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def onchange_partner_id(self, cr, uid, ids, partner_id, profile_id, context=None):
|
||||
"""
|
||||
Override of the basic method as we need to pass the profile_id in the on_change_type
|
||||
call.
|
||||
"""
|
||||
obj_partner = self.pool.get('res.partner')
|
||||
if context is None:
|
||||
context = {}
|
||||
if not partner_id:
|
||||
return {}
|
||||
part = obj_partner.browse(cr, uid, partner_id, context=context)
|
||||
@@ -543,23 +567,25 @@ class AccountBankSatementLine(Model):
|
||||
type = 'supplier'
|
||||
if part.customer == True:
|
||||
type = 'customer'
|
||||
res_type = self.onchange_type(cr, uid, ids, partner_id, type, profile_id, context=context) # Chg
|
||||
res_type = self.onchange_type(cr, uid, ids, partner_id, type, profile_id, context=context) # Chg
|
||||
if res_type['value'] and res_type['value'].get('account_id', False):
|
||||
return {'value': {'type': type, 'account_id': res_type['value']['account_id']}}
|
||||
return {'value': {'type': type}}
|
||||
|
||||
|
||||
def onchange_type(self, cr, uid, line_id, partner_id, type, profile_id, context=None):
|
||||
"""
|
||||
Keep the same features as in standard and call super. If an account is returned,
|
||||
call the method to compute line values.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(AccountBankSatementLine,self).onchange_type(cr, uid, line_id, partner_id, type, context)
|
||||
res = super(AccountBankSatementLine, self).onchange_type(
|
||||
cr, uid, line_id, partner_id, type, context=context)
|
||||
if 'account_id' in res['value']:
|
||||
result = self.get_values_for_line(cr, uid, profile_id = profile_id,
|
||||
partner_id = partner_id, line_type = type, context = context)
|
||||
result = self.get_values_for_line(
|
||||
cr, uid,
|
||||
profile_id=profile_id,
|
||||
partner_id=partner_id,
|
||||
line_type=type,
|
||||
context=context)
|
||||
if result:
|
||||
res['value'].update({'account_id':result['account_id']})
|
||||
res['value'].update({'account_id': result['account_id']})
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user