banking-addons-team team mailing list archive
-
banking-addons-team team
-
Mailing list archive
-
Message #00514
lp:~akretion-team/banking-addons/bank-statement-reconcile-61-ref-base-completion into lp:banking-addons/bank-statement-reconcile-61
Benoit Guillot - http://www.akretion.com has proposed merging lp:~akretion-team/banking-addons/bank-statement-reconcile-61-ref-base-completion into lp:banking-addons/bank-statement-reconcile-61.
Requested reviews:
Banking Addons Team (banking-addons-team)
For more details, see:
https://code.launchpad.net/~akretion-team/banking-addons/bank-statement-reconcile-61-ref-base-completion/+merge/159105
In this merge proposal, I submit some changes in the module account_statement_base_completion :
- add a hook for the field function_to_call
- remove to useless spaces at the end of lines due to my IDE
- fix typo in the name of the class : AccountBankStatement
The last point can be discuss :
- don't call automatically the method : get_values_for_line for each statement line that we want to complete
Indeed I think this method should be called in the rule if usefull (it's already the case in the rules already created), but not in every cases.
--
https://code.launchpad.net/~akretion-team/banking-addons/bank-statement-reconcile-61-ref-base-completion/+merge/159105
Your team Banking Addons Team is requested to review the proposed merge of lp:~akretion-team/banking-addons/bank-statement-reconcile-61-ref-base-completion into lp:banking-addons/bank-statement-reconcile-61.
=== modified file 'account_statement_base_completion/statement.py'
--- account_statement_base_completion/statement.py 2012-12-13 13:57:29 +0000
+++ account_statement_base_completion/statement.py 2013-04-16 08:43:32 +0000
@@ -42,34 +42,34 @@
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 @@
if result:
return result
return res
-
+
class AccountStatementCompletionRule(Model):
"""
@@ -93,15 +93,15 @@
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 @@
('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 @@
the statement line or {}
{'partner_id': value,
'account_id' : value,
-
+
...}
"""
st_obj = self.pool.get('account.bank.statement.line')
@@ -155,8 +158,8 @@
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 @@
the statement line or {}
{'partner_id': value,
'account_id' : value,
-
+
...}
"""
st_obj = self.pool.get('account.bank.statement.line')
@@ -184,13 +187,13 @@
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 @@
the statement line or {}
{'partner_id': value,
'account_id' : value,
-
+
...}
"""
partner_obj = self.pool.get('res.partner')
@@ -236,7 +239,7 @@
the statement line or {}
{'partner_id': value,
'account_id' : value,
-
+
...}
"""
# This Method has not been tested yet !
@@ -257,8 +260,8 @@
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 @@
_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 @@
_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 @@
: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 @@
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 @@
_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 @@
+ "\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 @@
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]
=== modified file 'account_statement_base_completion/statement_view.xml'
--- account_statement_base_completion/statement_view.xml 2012-08-02 12:46:12 +0000
+++ account_statement_base_completion/statement_view.xml 2013-04-16 08:43:32 +0000
@@ -23,7 +23,7 @@
<xpath expr="/form/group/field[@name='balance_end']" position="after">
<button name="button_auto_completion" string="Auto Completion" states='draft,open' type="object" colspan="1"/>
</xpath>
-
+
<xpath expr="/form/notebook/page[@string='Journal Entries']" position="after">
<page string="Completion Logs" attrs="{'invisible':[('completion_logs','=',False)]}">
<field name="completion_logs" colspan="4" nolabel="1" attrs="{'invisible':[('completion_logs','=',False)]}"/>
@@ -59,8 +59,8 @@
</field>
</field>
</record>
-
-
+
+
<record id="statement_st_completion_rule_view_form" model="ir.ui.view">
<field name="name">account.statement.completion.rule.view</field>
<field name="model">account.statement.completion.rule</field>
@@ -97,8 +97,8 @@
</record>
<menuitem string="Statement Completion Rule" action="action_st_completion_rule_tree"
- id="menu_action_st_completion_rule_tree_menu" parent="account.menu_configuration_misc"
+ id="menu_action_st_completion_rule_tree_menu" parent="account.menu_configuration_misc"
sequence="30"/>
-
+
</data>
</openerp>
Follow ups