mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[IMP] add a hook for field function_to_call, don't call default values for statement lines
This commit is contained in:
@@ -42,34 +42,34 @@ class AccountStatementProfil(Model):
|
||||
Extend the class to add rules per profile that will match at least the partner,
|
||||
but it could also be used to match other values as well.
|
||||
"""
|
||||
|
||||
|
||||
_inherit = "account.statement.profile"
|
||||
|
||||
|
||||
_columns={
|
||||
# @Akretion : For now, we don't implement this features, but this would probably be there:
|
||||
# 'auto_completion': fields.text('Auto Completion'),
|
||||
# 'transferts_account_id':fields.many2one('account.account', 'Transferts Account'),
|
||||
# => You can implement it in a module easily, we design it with your needs in mind
|
||||
# => You can implement it in a module easily, we design it with your needs in mind
|
||||
# as well !
|
||||
|
||||
'rule_ids':fields.many2many('account.statement.completion.rule',
|
||||
|
||||
'rule_ids':fields.many2many('account.statement.completion.rule',
|
||||
string='Related statement profiles',
|
||||
rel='as_rul_st_prof_rel',
|
||||
rel='as_rul_st_prof_rel',
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def find_values_from_rules(self, cr, uid, id, line_id, context=None):
|
||||
"""
|
||||
This method will execute all related rules, in their sequence order,
|
||||
This method will execute all related rules, in their sequence order,
|
||||
to retrieve all the values returned by the first rules that will match.
|
||||
|
||||
|
||||
:param int/long line_id: id of the concerned account.bank.statement.line
|
||||
:return:
|
||||
A dict of value that can be passed directly to the write method of
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
if not context:
|
||||
@@ -85,7 +85,7 @@ class AccountStatementProfil(Model):
|
||||
if result:
|
||||
return result
|
||||
return res
|
||||
|
||||
|
||||
|
||||
class AccountStatementCompletionRule(Model):
|
||||
"""
|
||||
@@ -93,15 +93,15 @@ class AccountStatementCompletionRule(Model):
|
||||
fullfill the bank statement lines. You'll be able to extend them in you own module
|
||||
and choose those to apply for every statement profile.
|
||||
The goal of a rule is to fullfill at least the partner of the line, but
|
||||
if possible also the reference because we'll use it in the reconciliation
|
||||
if possible also the reference because we'll use it in the reconciliation
|
||||
process. The reference should contain the invoice number or the SO number
|
||||
or any reference that will be matched by the invoice accounting move.
|
||||
"""
|
||||
|
||||
|
||||
_name = "account.statement.completion.rule"
|
||||
_order = "sequence asc"
|
||||
|
||||
def _get_functions(self, cr, uid, context=None):
|
||||
|
||||
def get_functions(self, cr, uid, context=None):
|
||||
"""
|
||||
List of available methods for rules. Override this to add you own.
|
||||
"""
|
||||
@@ -111,19 +111,22 @@ class AccountStatementCompletionRule(Model):
|
||||
('get_from_label_and_partner_field', 'From line label (based on partner field)'),
|
||||
('get_from_label_and_partner_name', 'From line label (based on partner name)'),
|
||||
]
|
||||
|
||||
|
||||
def _get_functions(self, cr, uid, context=None):
|
||||
return self.get_functions(cr, uid, context=context)
|
||||
|
||||
_columns={
|
||||
'sequence': fields.integer('Sequence', help="Lower means parsed first."),
|
||||
'name': fields.char('Name', size=128),
|
||||
'profile_ids': fields.many2many('account.statement.profile',
|
||||
rel='as_rul_st_prof_rel',
|
||||
'profile_ids': fields.many2many('account.statement.profile',
|
||||
rel='as_rul_st_prof_rel',
|
||||
string='Related statement profiles'),
|
||||
'function_to_call': fields.selection(_get_functions, 'Method'),
|
||||
}
|
||||
|
||||
|
||||
def get_from_ref_and_invoice(self, cursor, uid, line_id, context=None):
|
||||
"""
|
||||
Match the partner based on the invoice number and the reference of the statement
|
||||
Match the partner based on the invoice number and the reference of the statement
|
||||
line. Then, call the generic get_values_for_line method to complete other values.
|
||||
If more than one partner matched, raise the ErrorTooManyPartner error.
|
||||
|
||||
@@ -133,7 +136,7 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
@@ -155,8 +158,8 @@ class AccountStatementCompletionRule(Model):
|
||||
|
||||
def get_from_ref_and_so(self, cursor, uid, line_id, context=None):
|
||||
"""
|
||||
Match the partner based on the SO number and the reference of the statement
|
||||
line. Then, call the generic get_values_for_line method to complete other values.
|
||||
Match the partner based on the SO number and the reference of the statement
|
||||
line. Then, call the generic get_values_for_line method to complete other values.
|
||||
If more than one partner matched, raise the ErrorTooManyPartner error.
|
||||
|
||||
:param int/long line_id: id of the concerned account.bank.statement.line
|
||||
@@ -165,7 +168,7 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
@@ -184,13 +187,13 @@ class AccountStatementCompletionRule(Model):
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
res.update(st_vals)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def get_from_label_and_partner_field(self, cursor, uid, line_id, context=None):
|
||||
"""
|
||||
Match the partner based on the label field of the statement line
|
||||
and the text defined in the 'bank_statement_label' field of the partner.
|
||||
Remember that we can have values separated with ; Then, call the generic
|
||||
Remember that we can have values separated with ; Then, call the generic
|
||||
get_values_for_line method to complete other values.
|
||||
If more than one partner matched, raise the ErrorTooManyPartner error.
|
||||
|
||||
@@ -200,7 +203,7 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
@@ -236,7 +239,7 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
# This Method has not been tested yet !
|
||||
@@ -257,8 +260,8 @@ class AccountStatementCompletionRule(Model):
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
res.update(st_vals)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
class AccountStatementLine(Model):
|
||||
"""
|
||||
Add sparse field on the statement line to allow to store all the
|
||||
@@ -271,11 +274,11 @@ class AccountStatementLine(Model):
|
||||
_inherit = "account.bank.statement.line"
|
||||
|
||||
_columns={
|
||||
'additionnal_bank_fields' : fields.serialized('Additionnal infos from bank',
|
||||
'additionnal_bank_fields' : fields.serialized('Additionnal infos from bank',
|
||||
help="Used by completion and import system. Adds every field that is present in your bank/office \
|
||||
statement file"),
|
||||
'label': fields.sparse(type='char', string='Label',
|
||||
serialization_field='additionnal_bank_fields',
|
||||
'label': fields.sparse(type='char', string='Label',
|
||||
serialization_field='additionnal_bank_fields',
|
||||
help="Generiy field to store a label given from the bank/office on which we can \
|
||||
base the default/standard providen rule."),
|
||||
'already_completed': fields.boolean("Auto-Completed",
|
||||
@@ -284,8 +287,8 @@ class AccountStatementLine(Model):
|
||||
_defaults = {
|
||||
'already_completed': False,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
def get_line_values_from_rules(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
We'll try to find out the values related to the line based on rules setted on
|
||||
@@ -294,22 +297,22 @@ class AccountStatementLine(Model):
|
||||
:return:
|
||||
A dict of dict value that can be passed directly to the write method of
|
||||
the statement line or {}. The first dict has statement line ID as a key:
|
||||
{117009: {'partner_id': 100997, 'account_id': 489L}}
|
||||
{117009: {'partner_id': 100997, 'account_id': 489L}}
|
||||
"""
|
||||
profile_obj = self.pool.get('account.statement.profile')
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
res={}
|
||||
errors_stack = []
|
||||
for line in self.browse(cr,uid, ids, context):
|
||||
if not line.already_completed:
|
||||
try:
|
||||
# Take the default values
|
||||
res[line.id] = st_obj.get_values_for_line(cr, uid, profile_id = line.statement_id.profile_id.id,
|
||||
line_type = line.type, amount = line.amount, context = context)
|
||||
#Don't use default values, it should be called by the rules if needed
|
||||
#res[line.id] = self.get_values_for_line(cr, uid, profile_id = line.statement_id.profile_id.id,
|
||||
# line_type = line.type, amount = line.amount, context = context)
|
||||
# Ask the rule
|
||||
vals = profile_obj.find_values_from_rules(cr, uid, line.statement_id.profile_id.id, line.id, context)
|
||||
# Merge the result
|
||||
res[line.id].update(vals)
|
||||
if vals:
|
||||
res[line.id] = vals
|
||||
except ErrorTooManyPartner, exc:
|
||||
msg = "Line ID %s had following error: %s" % (line.id, exc.value)
|
||||
errors_stack.append(msg)
|
||||
@@ -317,8 +320,8 @@ class AccountStatementLine(Model):
|
||||
msg = u"\n".join(errors_stack)
|
||||
raise ErrorTooManyPartner(msg)
|
||||
return res
|
||||
|
||||
class AccountBankSatement(Model):
|
||||
|
||||
class AccountBankStatement(Model):
|
||||
"""
|
||||
We add a basic button and stuff to support the auto-completion
|
||||
of the bank statement once line have been imported or manually fullfill.
|
||||
@@ -328,18 +331,18 @@ class AccountBankSatement(Model):
|
||||
_columns = {
|
||||
'completion_logs': fields.text('Completion Log', readonly=True),
|
||||
}
|
||||
|
||||
|
||||
def write_completion_log(self, cr, uid, stat_id, error_msg, number_imported, context=None):
|
||||
"""
|
||||
Write the log in the completion_logs field of the bank statement to let the user
|
||||
know what have been done. This is an append mode, so we don't overwrite what
|
||||
already recoded.
|
||||
|
||||
|
||||
:param int/long stat_id: ID of the account.bank.statement
|
||||
:param char error_msg: Message to add
|
||||
:number_imported int/long: Number of lines that have been completed
|
||||
:return : True
|
||||
|
||||
|
||||
"""
|
||||
error_log = ""
|
||||
user_name = self.pool.get('res.users').read(cr, uid, uid, ['name'])['name']
|
||||
@@ -353,10 +356,10 @@ class AccountBankSatement(Model):
|
||||
+ "\n" + error_log + "-------------" + "\n"]
|
||||
log = "\n".join(log_line)
|
||||
self.write(cr, uid, [stat_id], {'completion_logs' : log}, context=context)
|
||||
logger.notifyChannel('Bank Statement Completion', netsvc.LOG_INFO,
|
||||
logger.notifyChannel('Bank Statement Completion', netsvc.LOG_INFO,
|
||||
"Bank Statement ID %s has %s lines completed"%(stat_id, number_imported))
|
||||
return True
|
||||
|
||||
|
||||
def button_auto_completion(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Complete line with values given by rules and tic the already_completed
|
||||
@@ -376,9 +379,9 @@ class AccountBankSatement(Model):
|
||||
if res:
|
||||
compl_lines += 1
|
||||
except ErrorTooManyPartner, exc:
|
||||
msg += exc.value + "\n"
|
||||
msg += exc.message + "\n"
|
||||
except Exception, exc:
|
||||
msg += exc.value + "\n"
|
||||
msg += exc.message + "\n"# TODO FIXME
|
||||
# vals = res and res.keys() or False
|
||||
if res:
|
||||
vals = res[line.id]
|
||||
|
||||
Reference in New Issue
Block a user