mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[MIGR] migration of bank-statement-reconcile to v7.0 done by Guewen Baconnier and myself.
The goal is to make the modules installable and to clean them to respect the quality standard expected by the community modules. Not to use the new shiny features of the new version 7. * Adapt view * Change the huge create_move_from_st_line method to take part of the v7.0 refactoring done by my previous merge ;) * Small fixes * Make installable = False on non-needed module * Formatting, pep8, pylint warnings Details in the nested log.
This commit is contained in:
@@ -117,4 +117,3 @@ class easy_reconcile_advanced_ref(TransientModel):
|
||||
yield ('partner_id', move_line['partner_id'])
|
||||
yield ('ref', (move_line['ref'].lower().strip(),
|
||||
move_line['name'].lower().strip()))
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
from itertools import groupby, product
|
||||
from operator import itemgetter
|
||||
from openerp.osv.orm import Model, AbstractModel, TransientModel
|
||||
from openerp.osv import fields
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
|
||||
class easy_reconcile_advanced(AbstractModel):
|
||||
@@ -271,4 +271,3 @@ class easy_reconcile_advanced(AbstractModel):
|
||||
partial_reconciled_ids += reconcile_group_ids
|
||||
|
||||
return reconciled_ids, partial_reconciled_ids
|
||||
|
||||
|
||||
@@ -34,4 +34,3 @@ class account_easy_reconcile_method(Model):
|
||||
'Advanced. Partner and Ref.'),
|
||||
]
|
||||
return methods
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import AbstractModel
|
||||
from openerp.osv import fields
|
||||
from openerp.osv import fields, osv
|
||||
from operator import itemgetter, attrgetter
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
import time
|
||||
from openerp.osv.orm import Model, AbstractModel
|
||||
from openerp.osv import fields
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
##############################################################################
|
||||
|
||||
import statement
|
||||
import partner
|
||||
import partner
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'complexity': 'normal',
|
||||
'depends': ['account_statement_ext'],
|
||||
'description': """
|
||||
The goal of this module is to improve the basic bank statement, help dealing with huge volume of
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
#################################################################################
|
||||
# #
|
||||
# Copyright (C) 2011 Akretion & Camptocamp
|
||||
@@ -19,9 +19,11 @@
|
||||
# #
|
||||
#################################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
class res_partner(osv.osv):
|
||||
|
||||
class res_partner(Model):
|
||||
"""
|
||||
Add a bank label on the partner so that we can use it to match
|
||||
this partner when we found this in a statement line.
|
||||
@@ -29,10 +31,8 @@ class res_partner(osv.osv):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
_columns = {
|
||||
'bank_statement_label':fields.char('Bank Statement Label', size=100,
|
||||
'bank_statement_label': fields.char('Bank Statement Label', size=100,
|
||||
help="Enter the various label found on your bank statement separated by a ; If \
|
||||
one of this label is include in the bank statement line, the partner will be automatically \
|
||||
filled (as long as you use this method/rules in your statement profile)."),
|
||||
}
|
||||
|
||||
res_partner()
|
||||
|
||||
@@ -19,13 +19,12 @@
|
||||
#
|
||||
##############################################################################
|
||||
from tools.translate import _
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.osv import fields, osv
|
||||
from operator import itemgetter, attrgetter
|
||||
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from operator import attrgetter
|
||||
import datetime
|
||||
|
||||
|
||||
class ErrorTooManyPartner(Exception):
|
||||
"""
|
||||
New Exception definition that is raised when more than one partner is matched by
|
||||
@@ -33,6 +32,7 @@ class ErrorTooManyPartner(Exception):
|
||||
"""
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
@@ -42,38 +42,38 @@ 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={
|
||||
|
||||
_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:
|
||||
context={}
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
rule_obj = self.pool.get('account.statement.completion.rule')
|
||||
profile = self.browse(cr, uid, id, context=context)
|
||||
@@ -81,11 +81,11 @@ class AccountStatementProfil(Model):
|
||||
sorted_array = sorted(profile.rule_ids, key=attrgetter('sequence'))
|
||||
for rule in sorted_array:
|
||||
method_to_call = getattr(rule_obj, rule.function_to_call)
|
||||
result = method_to_call(cr,uid,line_id,context)
|
||||
result = method_to_call(cr, uid, line_id, context)
|
||||
if result:
|
||||
return result
|
||||
return res
|
||||
|
||||
|
||||
|
||||
class AccountStatementCompletionRule(Model):
|
||||
"""
|
||||
@@ -93,14 +93,14 @@ 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):
|
||||
"""
|
||||
List of available methods for rules. Override this to add you own.
|
||||
@@ -111,19 +111,20 @@ 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)'),
|
||||
]
|
||||
|
||||
_columns={
|
||||
|
||||
_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):
|
||||
|
||||
def get_from_ref_and_invoice(self, cr, 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,30 +134,42 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
st_line = st_obj.browse(cursor,uid,line_id)
|
||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||
res = {}
|
||||
if st_line:
|
||||
inv_obj = self.pool.get('account.invoice')
|
||||
inv_id = inv_obj.search(cursor, uid, [('number', '=', st_line.ref)])
|
||||
inv_id = inv_obj.search(
|
||||
cr,
|
||||
uid,
|
||||
[('number', '=', st_line.ref)],
|
||||
context=context)
|
||||
if inv_id:
|
||||
if inv_id and len(inv_id) == 1:
|
||||
inv = inv_obj.browse(cursor, uid, inv_id[0])
|
||||
inv = inv_obj.browse(cr, uid, inv_id[0], context=context)
|
||||
res['partner_id'] = inv.partner_id.id
|
||||
elif inv_id and len(inv_id) > 1:
|
||||
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
|
||||
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
raise ErrorTooManyPartner(
|
||||
_('Line named "%s" (Ref:%s) was matched by more '
|
||||
'than one partner.') % (st_line.name, st_line.ref))
|
||||
st_vals = st_obj.get_values_for_line(
|
||||
cr,
|
||||
uid,
|
||||
profile_id=st_line.statement_id.profile_id.id,
|
||||
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_ref_and_so(self, cursor, uid, line_id, context=None):
|
||||
def get_from_ref_and_so(self, cr, 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,32 +178,44 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
st_line = st_obj.browse(cursor,uid,line_id)
|
||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||
res = {}
|
||||
if st_line:
|
||||
so_obj = self.pool.get('sale.order')
|
||||
so_id = so_obj.search(cursor, uid, [('name', '=', st_line.ref)])
|
||||
so_id = so_obj.search(
|
||||
cr,
|
||||
uid,
|
||||
[('name', '=', st_line.ref)],
|
||||
context=context)
|
||||
if so_id:
|
||||
if so_id and len(so_id) == 1:
|
||||
so = so_obj.browse(cursor, uid, so_id[0])
|
||||
so = so_obj.browse(cr, uid, so_id[0], context=context)
|
||||
res['partner_id'] = so.partner_id.id
|
||||
elif so_id and len(so_id) > 1:
|
||||
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
|
||||
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
raise ErrorTooManyPartner(
|
||||
_('Line named "%s" (Ref:%s) was matched by more '
|
||||
'than one partner.') %
|
||||
(st_line.name, st_line.ref))
|
||||
st_vals = st_obj.get_values_for_line(
|
||||
cr,
|
||||
uid,
|
||||
profile_id=st_line.statement_id.profile_id.id,
|
||||
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):
|
||||
def get_from_label_and_partner_field(self, cr, 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,30 +225,43 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
st_line = st_obj.browse(cursor,uid,line_id)
|
||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||
res = {}
|
||||
compt = 0
|
||||
if st_line:
|
||||
ids = partner_obj.search(cursor, uid, [['bank_statement_label', '!=', False]], context=context)
|
||||
for partner in partner_obj.browse(cursor, uid, ids, context=context):
|
||||
ids = partner_obj.search(
|
||||
cr,
|
||||
uid,
|
||||
[('bank_statement_label', '!=', False)],
|
||||
context=context)
|
||||
for partner in partner_obj.browse(cr, uid, ids, context=context):
|
||||
for partner_label in partner.bank_statement_label.split(';'):
|
||||
if partner_label in st_line.label:
|
||||
compt += 1
|
||||
res['partner_id'] = partner.id
|
||||
if compt > 1:
|
||||
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
|
||||
raise ErrorTooManyPartner(
|
||||
_('Line named "%s" (Ref:%s) was matched by '
|
||||
'more than one partner.') %
|
||||
(st_line.name, st_line.ref))
|
||||
if res:
|
||||
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
st_vals = st_obj.get_values_for_line(
|
||||
cr,
|
||||
uid,
|
||||
profile_id=st_line.statement_id.profile_id.id,
|
||||
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_name(self, cursor, uid, line_id, context=None):
|
||||
def get_from_label_and_partner_name(self, cr, uid, line_id, context=None):
|
||||
"""
|
||||
Match the partner based on the label field of the statement line
|
||||
and the name of the partner.
|
||||
@@ -236,29 +274,38 @@ class AccountStatementCompletionRule(Model):
|
||||
the statement line or {}
|
||||
{'partner_id': value,
|
||||
'account_id' : value,
|
||||
|
||||
|
||||
...}
|
||||
"""
|
||||
# This Method has not been tested yet !
|
||||
res = {}
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
st_line = st_obj.browse(cursor,uid,line_id)
|
||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||
if st_line:
|
||||
sql = "SELECT id FROM res_partner WHERE name ~* %s"
|
||||
pattern = ".*%s.*" % st_line.label
|
||||
cursor.execute(sql, (pattern,))
|
||||
result = cursor.fetchall()
|
||||
cr.execute(sql, (pattern,))
|
||||
result = cr.fetchall()
|
||||
if len(result) > 1:
|
||||
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
|
||||
raise ErrorTooManyPartner(
|
||||
_('Line named "%s" (Ref:%s) was matched by more '
|
||||
'than one partner.') %
|
||||
(st_line.name, st_line.ref))
|
||||
for id in result[0]:
|
||||
res['partner_id'] = id
|
||||
if res:
|
||||
st_vals = st_obj.get_values_for_line(cursor, uid, profile_id = st_line.statement_id.profile_id.id,
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context = context)
|
||||
st_vals = st_obj.get_values_for_line(
|
||||
cr,
|
||||
uid,
|
||||
profile_id=st_line.statement_id.profile_id.id,
|
||||
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
|
||||
@@ -270,22 +317,28 @@ class AccountStatementLine(Model):
|
||||
"""
|
||||
_inherit = "account.bank.statement.line"
|
||||
|
||||
_columns={
|
||||
'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',
|
||||
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",
|
||||
help="When this checkbox is ticked, the auto-completion process/button will ignore this line."),
|
||||
_columns = {
|
||||
'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',
|
||||
help="Generic 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",
|
||||
help="When this checkbox is ticked, the auto-completion "
|
||||
"process/button will ignore this line."),
|
||||
}
|
||||
|
||||
_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,30 +347,38 @@ 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={}
|
||||
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)
|
||||
# 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)
|
||||
except ErrorTooManyPartner, exc:
|
||||
msg = "Line ID %s had following error: %s" % (line.id, exc.value)
|
||||
errors_stack.append(msg)
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.already_completed:
|
||||
continue
|
||||
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)
|
||||
# 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)
|
||||
except ErrorTooManyPartner, exc:
|
||||
msg = "Line ID %s had following error: %s" % (line.id, exc.value)
|
||||
errors_stack.append(msg)
|
||||
if errors_stack:
|
||||
msg = u"\n".join(errors_stack)
|
||||
raise ErrorTooManyPartner(msg)
|
||||
return res
|
||||
|
||||
|
||||
|
||||
class AccountBankSatement(Model):
|
||||
"""
|
||||
We add a basic button and stuff to support the auto-completion
|
||||
@@ -328,42 +389,46 @@ 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']
|
||||
log = self.read(cr, uid, stat_id, ['completion_logs'], context=context)['completion_logs']
|
||||
user_name = self.pool.get('res.users').read(
|
||||
cr, uid, uid, ['name'], context=context)['name']
|
||||
log = self.read(
|
||||
cr, uid, stat_id, ['completion_logs'], context=context)['completion_logs']
|
||||
log_line = log and log.split("\n") or []
|
||||
completion_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
completion_date = datetime.datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
if error_msg:
|
||||
error_log = error_msg
|
||||
log_line[0:0] = [completion_date + ' : '
|
||||
+ _("Bank Statement ID %s has %s lines completed by %s") %(stat_id, number_imported, user_name)
|
||||
+ _("Bank Statement ID %s has %s lines completed by %s") % (stat_id, number_imported, user_name)
|
||||
+ "\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,
|
||||
"Bank Statement ID %s has %s lines completed"%(stat_id, number_imported))
|
||||
self.write(cr, uid, [stat_id], {'completion_logs': log}, context=context)
|
||||
self.message_post(
|
||||
cr, uid,
|
||||
[stat_id],
|
||||
body=_('Statement ID %s auto-completed for %s lines completed') % (stat_id, number_imported),
|
||||
context=context)
|
||||
return True
|
||||
|
||||
|
||||
def button_auto_completion(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Complete line with values given by rules and tic the already_completed
|
||||
checkbox so we won't compute them again unless the user untick them !
|
||||
"""
|
||||
if not context:
|
||||
context={}
|
||||
if context is None:
|
||||
context = {}
|
||||
stat_line_obj = self.pool.get('account.bank.statement.line')
|
||||
msg = ""
|
||||
compl_lines = 0
|
||||
@@ -372,7 +437,8 @@ class AccountBankSatement(Model):
|
||||
for line in stat.line_ids:
|
||||
res = {}
|
||||
try:
|
||||
res = stat_line_obj.get_line_values_from_rules(cr, uid, [line.id], context=ctx)
|
||||
res = stat_line_obj.get_line_values_from_rules(
|
||||
cr, uid, [line.id], context=ctx)
|
||||
if res:
|
||||
compl_lines += 1
|
||||
except ErrorTooManyPartner, exc:
|
||||
@@ -383,6 +449,7 @@ class AccountBankSatement(Model):
|
||||
if res:
|
||||
vals = res[line.id]
|
||||
vals['already_completed'] = True
|
||||
stat_line_obj.write(cr, uid, line.id, vals, context=ctx)
|
||||
self.write_completion_log(cr, uid, stat.id, msg, compl_lines, context=context)
|
||||
stat_line_obj.write(cr, uid, [line.id], vals, context=ctx)
|
||||
self.write_completion_log(
|
||||
cr, uid, stat.id, msg, compl_lines, context=context)
|
||||
return True
|
||||
|
||||
@@ -10,21 +10,21 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page/field[@name='line_ids']/form/field[@name='sequence']" position="after">
|
||||
<xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/form/group/field[@name='sequence']" position="after">
|
||||
<separator colspan="4" string="Importation related infos"/>
|
||||
<field name="label" />
|
||||
<field name="already_completed" />
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/group[2]" position="attributes">
|
||||
<attribute name="col">10</attribute>
|
||||
</xpath>
|
||||
<!-- <xpath expr="/form/group[2]" position="attributes">
|
||||
<attribute name="col">10</attribute>
|
||||
</xpath> -->
|
||||
|
||||
<xpath expr="/form/group/field[@name='balance_end']" position="after">
|
||||
<xpath expr="/form/sheet/div[@name='import_buttons']" 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">
|
||||
<xpath expr="/form/sheet/notebook/page[@string='Transactions']" position="after">
|
||||
<page string="Completion Logs" attrs="{'invisible':[('completion_logs','=',False)]}">
|
||||
<field name="completion_logs" colspan="4" nolabel="1" attrs="{'invisible':[('completion_logs','=',False)]}"/>
|
||||
</page>
|
||||
@@ -40,7 +40,7 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page/field[@name='line_ids']/tree/field[@name='amount']" position="after">
|
||||
<xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/tree/field[@name='amount']" position="after">
|
||||
<field name="already_completed" />
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
##############################################################################
|
||||
import parser
|
||||
import wizard
|
||||
import statement
|
||||
import statement
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account_statement_ext','account_statement_base_completion'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account_statement_ext',
|
||||
'account_statement_base_completion'
|
||||
],
|
||||
'description': """
|
||||
This module brings basic methods and fields on bank statement to deal with
|
||||
the importation of different bank and offices. A generic abstract method is defined and an
|
||||
|
||||
@@ -22,4 +22,4 @@
|
||||
from parser import new_bank_statement_parser
|
||||
from parser import BankStatementImportParser
|
||||
import file_parser
|
||||
import generic_file_parser
|
||||
import generic_file_parser
|
||||
|
||||
@@ -28,17 +28,18 @@ try:
|
||||
except:
|
||||
raise Exception(_('Please install python lib xlrd'))
|
||||
|
||||
|
||||
class FileParser(BankStatementImportParser):
|
||||
"""
|
||||
Generic abstract class for defining parser for .csv or .xls file format.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parse_name, keys_to_validate=[], ftype='csv', convertion_dict=None, header=None, *args, **kwargs):
|
||||
"""
|
||||
:param char: parse_name : The name of the parser
|
||||
:param list: keys_to_validate : contain the key that need to be present in the file
|
||||
:param char ftype: extension of the file (could be csv or xls)
|
||||
:param: convertion_dict : keys and type to convert of every column in the file like
|
||||
:param: convertion_dict : keys and type to convert of every column in the file like
|
||||
{
|
||||
'ref': unicode,
|
||||
'label': unicode,
|
||||
@@ -48,7 +49,7 @@ class FileParser(BankStatementImportParser):
|
||||
}
|
||||
:param list: header : specify header fields if the csv file has no header
|
||||
"""
|
||||
|
||||
|
||||
super(FileParser, self).__init__(parse_name, *args, **kwargs)
|
||||
if ftype in ('csv', 'xls'):
|
||||
self.ftype = ftype
|
||||
@@ -57,9 +58,9 @@ class FileParser(BankStatementImportParser):
|
||||
self.keys_to_validate = keys_to_validate
|
||||
self.convertion_dict = convertion_dict
|
||||
self.fieldnames = header
|
||||
self._datemode = 0 # used only for xls documents,
|
||||
# 0 means Windows mode (1900 based dates).
|
||||
# Set in _parse_xls, from the contents of the file
|
||||
self._datemode = 0 # used only for xls documents,
|
||||
# 0 means Windows mode (1900 based dates).
|
||||
# Set in _parse_xls, from the contents of the file
|
||||
|
||||
def _custom_format(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -78,7 +79,7 @@ class FileParser(BankStatementImportParser):
|
||||
Launch the parsing through .csv or .xls depending on the
|
||||
given ftype
|
||||
"""
|
||||
|
||||
|
||||
res = None
|
||||
if self.ftype == 'csv':
|
||||
res = self._parse_csv()
|
||||
@@ -108,7 +109,6 @@ class FileParser(BankStatementImportParser):
|
||||
self.result_row_list = self._cast_rows(*args, **kwargs)
|
||||
return True
|
||||
|
||||
|
||||
def _parse_csv(self):
|
||||
"""
|
||||
:return: list of dict from csv file (line/rows)
|
||||
@@ -116,7 +116,7 @@ class FileParser(BankStatementImportParser):
|
||||
csv_file = tempfile.NamedTemporaryFile()
|
||||
csv_file.write(self.filebuffer)
|
||||
csv_file.flush()
|
||||
with open(csv_file.name, 'rU') as fobj:
|
||||
with open(csv_file.name, 'rU') as fobj:
|
||||
reader = UnicodeDictReader(fobj, fieldnames=self.fieldnames)
|
||||
return list(reader)
|
||||
|
||||
@@ -138,7 +138,7 @@ class FileParser(BankStatementImportParser):
|
||||
try:
|
||||
wb_file.close()
|
||||
except Exception, e:
|
||||
pass #file is allready closed
|
||||
pass # file is already closed
|
||||
return res
|
||||
|
||||
def _from_csv(self, result_set, conversion_rules):
|
||||
@@ -175,6 +175,6 @@ class FileParser(BankStatementImportParser):
|
||||
Convert the self.result_row_list using the self.convertion_dict providen.
|
||||
We call here _from_xls or _from_csv depending on the self.ftype variable.
|
||||
"""
|
||||
func = getattr(self, '_from_%s'%(self.ftype))
|
||||
func = getattr(self, '_from_%s' % self.ftype)
|
||||
res = func(self.result_row_list, self.convertion_dict)
|
||||
return res
|
||||
|
||||
@@ -23,20 +23,20 @@ import base64
|
||||
import csv
|
||||
import tempfile
|
||||
import datetime
|
||||
# from . import file_parser
|
||||
from file_parser import FileParser
|
||||
try:
|
||||
import xlrd
|
||||
except:
|
||||
raise Exception(_('Please install python lib xlrd'))
|
||||
|
||||
|
||||
class GenericFileParser(FileParser):
|
||||
"""
|
||||
Standard parser that use a define format in csv or xls to import into a
|
||||
bank statement. This is mostely an example of how to proceed to create a new
|
||||
bank statement. This is mostely an example of how to proceed to create a new
|
||||
parser, but will also be useful as it allow to import a basic flat file.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parse_name, ftype='csv'):
|
||||
convertion_dict = {
|
||||
'ref': unicode,
|
||||
@@ -47,7 +47,7 @@ class GenericFileParser(FileParser):
|
||||
}
|
||||
# Order of cols does not matter but first row of the file has to be header
|
||||
keys_to_validate = ['ref', 'label', 'date', 'amount', 'commission_amount']
|
||||
super(GenericFileParser,self).__init__(parse_name, keys_to_validate=keys_to_validate, ftype=ftype, convertion_dict=convertion_dict)
|
||||
super(GenericFileParser, self).__init__(parse_name, keys_to_validate=keys_to_validate, ftype=ftype, convertion_dict=convertion_dict)
|
||||
|
||||
@classmethod
|
||||
def parser_for(cls, parser_name):
|
||||
@@ -60,7 +60,7 @@ class GenericFileParser(FileParser):
|
||||
def get_st_line_vals(self, line, *args, **kwargs):
|
||||
"""
|
||||
This method must return a dict of vals that can be passed to create
|
||||
method of statement line in order to record it. It is the responsibility
|
||||
method of statement line in order to record it. It is the responsibility
|
||||
of every parser to give this dict of vals, so each one can implement his
|
||||
own way of recording the lines.
|
||||
:param: line: a dict of vals that represent a line of result_row_list
|
||||
@@ -78,11 +78,11 @@ class GenericFileParser(FileParser):
|
||||
for each one.
|
||||
"""
|
||||
return {
|
||||
'name': line.get('label', line.get('ref','/')),
|
||||
'name': line.get('label', line.get('ref', '/')),
|
||||
'date': line.get('date', datetime.datetime.now().date()),
|
||||
'amount': line.get('amount', 0.0),
|
||||
'ref': line.get('ref','/'),
|
||||
'label': line.get('label',''),
|
||||
'ref': line.get('ref', '/'),
|
||||
'label': line.get('label', ''),
|
||||
'commission_amount': line.get('commission_amount', 0.0),
|
||||
}
|
||||
|
||||
@@ -93,10 +93,6 @@ class GenericFileParser(FileParser):
|
||||
res = super(GenericFileParser, self)._post(*args, **kwargs)
|
||||
val = 0.0
|
||||
for row in self.result_row_list:
|
||||
val += row.get('commission_amount',0.0)
|
||||
val += row.get('commission_amount', 0.0)
|
||||
self.commission_global_amount = val
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
import base64
|
||||
import csv
|
||||
|
||||
|
||||
def UnicodeDictReader(utf8_data, **kwargs):
|
||||
sniffer = csv.Sniffer()
|
||||
pos = utf8_data.tell()
|
||||
@@ -31,6 +32,7 @@ def UnicodeDictReader(utf8_data, **kwargs):
|
||||
for row in csv_reader:
|
||||
yield dict([(key, unicode(value, 'utf-8')) for key, value in row.iteritems()])
|
||||
|
||||
|
||||
class BankStatementImportParser(object):
|
||||
"""
|
||||
Generic abstract class for defining parser for different files and
|
||||
@@ -38,7 +40,7 @@ class BankStatementImportParser(object):
|
||||
own. If your file is a .csv or .xls format, you should consider inheirt
|
||||
from the FileParser instead.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parser_name, *args, **kwargs):
|
||||
# The name of the parser as it will be called
|
||||
self.parser_name = parser_name
|
||||
@@ -50,7 +52,7 @@ class BankStatementImportParser(object):
|
||||
# Concatenate here the global commission taken by the bank/office
|
||||
# for this statement.
|
||||
self.commission_global_amount = None
|
||||
|
||||
|
||||
@classmethod
|
||||
def parser_for(cls, parser_name):
|
||||
"""
|
||||
@@ -58,17 +60,17 @@ class BankStatementImportParser(object):
|
||||
return the good class from his name.
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
def _decode_64b_stream(self):
|
||||
"""
|
||||
Decode self.filebuffer in base 64 and override it
|
||||
"""
|
||||
self.filebuffer = base64.b64decode(self.filebuffer)
|
||||
return True
|
||||
|
||||
|
||||
def _format(self, decode_base_64=True, **kwargs):
|
||||
"""
|
||||
Decode into base 64 if asked and Format the given filebuffer by calling
|
||||
Decode into base 64 if asked and Format the given filebuffer by calling
|
||||
_custom_format method.
|
||||
"""
|
||||
if decode_base_64:
|
||||
@@ -83,43 +85,40 @@ class BankStatementImportParser(object):
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
|
||||
def _pre(self, *args, **kwargs):
|
||||
"""
|
||||
Implement a method in your parser to make a pre-treatment on datas before parsing
|
||||
Implement a method in your parser to make a pre-treatment on datas before parsing
|
||||
them, like concatenate stuff, and so... Work on self.filebuffer
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
def _parse(self, *args, **kwargs):
|
||||
"""
|
||||
Implement a method in your parser to save the result of parsing self.filebuffer
|
||||
Implement a method in your parser to save the result of parsing self.filebuffer
|
||||
in self.result_row_list instance property.
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
|
||||
def _validate(self, *args, **kwargs):
|
||||
"""
|
||||
Implement a method in your parser to validate the self.result_row_list instance
|
||||
property and raise an error if not valid.
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
|
||||
def _post(self, *args, **kwargs):
|
||||
"""
|
||||
Implement a method in your parser to make some last changes on the result of parsing
|
||||
the datas, like converting dates, computing commission, ...
|
||||
the datas, like converting dates, computing commission, ...
|
||||
Work on self.result_row_list and put the commission global amount if any
|
||||
in the self.commission_global_amount one.
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
|
||||
|
||||
def get_st_line_vals(self, line, *args, **kwargs):
|
||||
"""
|
||||
Implement a method in your parser that must return a dict of vals that can be
|
||||
passed to create method of statement line in order to record it. It is the responsibility
|
||||
Implement a method in your parser that must return a dict of vals that can be
|
||||
passed to create method of statement line in order to record it. It is the responsibility
|
||||
of every parser to give this dict of vals, so each one can implement his
|
||||
own way of recording the lines.
|
||||
:param: line: a dict of vals that represent a line of result_row_list
|
||||
@@ -133,17 +132,17 @@ class BankStatementImportParser(object):
|
||||
}
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
|
||||
def get_st_line_commision(self, *args, **kwargs):
|
||||
"""
|
||||
This is called by the importation method to create the commission line in
|
||||
the bank statement. We will always create one line for the commission in the
|
||||
bank statement, but it could be computated from a value of each line, or given
|
||||
bank statement, but it could be computated from a value of each line, or given
|
||||
in a single line for the whole file.
|
||||
return: float of the whole commission (self.commission_global_amount)
|
||||
"""
|
||||
return self.commission_global_amount
|
||||
|
||||
|
||||
def parse(self, filebuffer, *args, **kwargs):
|
||||
"""
|
||||
This will be the method that will be called by wizard, button and so
|
||||
@@ -151,7 +150,7 @@ class BankStatementImportParser(object):
|
||||
that need to be define for each parser.
|
||||
Return:
|
||||
[] of rows as {'key':value}
|
||||
|
||||
|
||||
Note: The row_list must contain only value that are present in the account.
|
||||
bank.statement.line object !!!
|
||||
"""
|
||||
@@ -165,7 +164,8 @@ class BankStatementImportParser(object):
|
||||
self._validate(*args, **kwargs)
|
||||
self._post(*args, **kwargs)
|
||||
return self.result_row_list
|
||||
|
||||
|
||||
|
||||
def itersubclasses(cls, _seen=None):
|
||||
"""
|
||||
itersubclasses(cls)
|
||||
@@ -179,7 +179,7 @@ def itersubclasses(cls, _seen=None):
|
||||
>>> class C(A): pass
|
||||
>>> class D(B,C): pass
|
||||
>>> class E(D): pass
|
||||
>>>
|
||||
>>>
|
||||
>>> for cls in itersubclasses(A):
|
||||
... print(cls.__name__)
|
||||
B
|
||||
@@ -193,10 +193,11 @@ def itersubclasses(cls, _seen=None):
|
||||
if not isinstance(cls, type):
|
||||
raise TypeError('itersubclasses must be called with '
|
||||
'new-style classes, not %.100r' % cls)
|
||||
if _seen is None: _seen = set()
|
||||
if _seen is None:
|
||||
_seen = set()
|
||||
try:
|
||||
subs = cls.__subclasses__()
|
||||
except TypeError: # fails only when cls is type
|
||||
except TypeError: # fails only when cls is type
|
||||
subs = cls.__subclasses__(cls)
|
||||
for sub in subs:
|
||||
if sub not in _seen:
|
||||
@@ -204,7 +205,8 @@ def itersubclasses(cls, _seen=None):
|
||||
yield sub
|
||||
for sub in itersubclasses(sub, _seen):
|
||||
yield sub
|
||||
|
||||
|
||||
|
||||
def new_bank_statement_parser(parser_name, *args, **kwargs):
|
||||
"""
|
||||
Return an instance of the good parser class base on the providen name
|
||||
@@ -215,4 +217,3 @@ def new_bank_statement_parser(parser_name, *args, **kwargs):
|
||||
if cls.parser_for(parser_name):
|
||||
return cls(parser_name, *args, **kwargs)
|
||||
raise ValueError
|
||||
|
||||
|
||||
@@ -19,64 +19,69 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from tools.translate import _
|
||||
from openerp.tools.translate import _
|
||||
import datetime
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields, osv
|
||||
# from account_statement_base_import.parser.file_parser import FileParser
|
||||
from parser import new_bank_statement_parser
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
|
||||
class AccountStatementProfil(Model):
|
||||
_inherit = "account.statement.profile"
|
||||
|
||||
|
||||
|
||||
def get_import_type_selection(self, cr, uid, context=None):
|
||||
"""
|
||||
Has to be inherited to add parser
|
||||
"""
|
||||
return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')]
|
||||
|
||||
|
||||
|
||||
_columns = {
|
||||
'launch_import_completion': fields.boolean("Launch completion after import",
|
||||
help="Tic that box to automatically launch the completion on each imported\
|
||||
file using this profile."),
|
||||
'launch_import_completion': fields.boolean(
|
||||
"Launch completion after import",
|
||||
help="Tic that box to automatically launch the completion "
|
||||
"on each imported file using this profile."),
|
||||
'last_import_date': fields.datetime("Last Import Date"),
|
||||
'rec_log': fields.text('log', readonly=True),
|
||||
'import_type': fields.selection(get_import_type_selection, 'Type of import', required=True,
|
||||
help = "Choose here the method by which you want to import bank statement for this profile."),
|
||||
|
||||
'import_type': fields.selection(
|
||||
get_import_type_selection,
|
||||
'Type of import',
|
||||
required=True,
|
||||
help="Choose here the method by which you want to import bank"
|
||||
"statement for this profile."),
|
||||
|
||||
}
|
||||
|
||||
|
||||
def write_logs_after_import(self, cr, uid, ids, statement_id, num_lines, context):
|
||||
"""
|
||||
Write the log in the logger + in the log field of the profile to report the user about
|
||||
Write the log in the logger + in the log field of the profile to report the user about
|
||||
what has been done.
|
||||
|
||||
|
||||
:param int/long statement_id: ID of the concerned account.bank.statement
|
||||
:param int/long num_lines: Number of line that have been parsed
|
||||
:return: True
|
||||
"""
|
||||
if type(ids) is int:
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
for id in ids:
|
||||
log = self.read(cr, uid, id, ['rec_log'], context=context)['rec_log']
|
||||
log_line = log and log.split("\n") or []
|
||||
import_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
log_line[0:0] = [import_date + ' : '
|
||||
+ _("Bank Statement ID %s have been imported with %s lines ") %(statement_id, num_lines)]
|
||||
+ _("Bank Statement ID %s have been imported with %s lines ") % (statement_id, num_lines)]
|
||||
log = "\n".join(log_line)
|
||||
self.write(cr, uid, id, {'rec_log' : log, 'last_import_date':import_date}, context=context)
|
||||
logger.notifyChannel('Bank Statement Import', netsvc.LOG_INFO,
|
||||
"Bank Statement ID %s have been imported with %s lines "%(statement_id, num_lines))
|
||||
self.write(cr, uid, id, {'rec_log': log, 'last_import_date': import_date}, context=context)
|
||||
self.message_post(
|
||||
cr,
|
||||
uid,
|
||||
[statement_id],
|
||||
body=_('Statement ID %s have been imported with %s lines.') % (statement_id, num_lines),
|
||||
context=context)
|
||||
return True
|
||||
|
||||
def prepare_global_commission_line_vals(self, cr, uid, parser,
|
||||
result_row_list, profile, statement_id, context):
|
||||
|
||||
def prepare_global_commission_line_vals(
|
||||
self, cr, uid, parser, result_row_list, profile, statement_id, context):
|
||||
"""
|
||||
Prepare the global commission line if there is one. The global
|
||||
commission is computed by by calling the get_st_line_commision
|
||||
@@ -95,9 +100,8 @@ class AccountStatementProfil(Model):
|
||||
partner_id = profile.partner_id and profile.partner_id.id or False
|
||||
commission_account_id = profile.commission_account_id and profile.commission_account_id.id or False
|
||||
commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
comm_values = {
|
||||
'name': 'IN '+ _('Commission line'),
|
||||
'name': 'IN ' + _('Commission line'),
|
||||
'date': datetime.datetime.now().date(),
|
||||
'amount': parser.get_st_line_commision(),
|
||||
'partner_id': partner_id,
|
||||
@@ -110,15 +114,16 @@ class AccountStatementProfil(Model):
|
||||
'already_completed': True,
|
||||
}
|
||||
return comm_values
|
||||
|
||||
def prepare_statetement_lines_vals(self, cursor, uid, parser_vals,
|
||||
account_payable, account_receivable, statement_id, context):
|
||||
|
||||
def prepare_statetement_lines_vals(
|
||||
self, cr, uid, parser_vals, account_payable, account_receivable,
|
||||
statement_id, context):
|
||||
"""
|
||||
Hook to build the values of a line from the parser returned values. At
|
||||
least it fullfill the statement_id and account_id. Overide it to add your
|
||||
own completion if needed.
|
||||
|
||||
:param dict of vals from parser for account.bank.statement.line (called by
|
||||
own completion if needed.
|
||||
|
||||
:param dict of vals from parser for account.bank.statement.line (called by
|
||||
parser.get_st_line_vals)
|
||||
:param int/long account_payable: ID of the receivable account to use
|
||||
:param int/long account_receivable: ID of the payable account to use
|
||||
@@ -127,30 +132,29 @@ class AccountStatementProfil(Model):
|
||||
"""
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
values = parser_vals
|
||||
values['statement_id']= statement_id
|
||||
values['statement_id'] = statement_id
|
||||
values['account_id'] = statement_obj.get_account_for_counterpart(
|
||||
cursor,
|
||||
cr,
|
||||
uid,
|
||||
parser_vals['amount'],
|
||||
account_receivable,
|
||||
account_payable
|
||||
)
|
||||
return values
|
||||
|
||||
def statement_import(self, cursor, uid, ids, profile_id, file_stream, ftype="csv", context=None):
|
||||
|
||||
def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None):
|
||||
"""
|
||||
Create a bank statement with the given profile and parser. It will fullfill the bank statement
|
||||
with the values of the file providen, but will not complete data (like finding the partner, or
|
||||
the right account). This will be done in a second step with the completion rules.
|
||||
It will also create the commission line if it apply and record the providen file as
|
||||
an attachement of the bank statement.
|
||||
|
||||
|
||||
:param int/long profile_id: ID of the profile used to import the file
|
||||
:param filebuffer file_stream: binary of the providen file
|
||||
:param char: ftype represent the file exstension (csv by default)
|
||||
:return: ID of the created account.bank.statemênt
|
||||
"""
|
||||
context = context or {}
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
attachment_obj = self.pool.get('ir.attachment')
|
||||
@@ -159,8 +163,8 @@ class AccountStatementProfil(Model):
|
||||
raise osv.except_osv(
|
||||
_("No Profile !"),
|
||||
_("You must provide a valid profile to import a bank statement !"))
|
||||
prof = prof_obj.browse(cursor,uid,profile_id,context)
|
||||
|
||||
prof = prof_obj.browse(cr, uid, profile_id, context=context)
|
||||
|
||||
parser = new_bank_statement_parser(prof.import_type, ftype=ftype)
|
||||
result_row_list = parser.parse(file_stream)
|
||||
# Check all key are present in account.bank.statement.line !!
|
||||
@@ -169,55 +173,60 @@ class AccountStatementProfil(Model):
|
||||
if col not in statement_line_obj._columns:
|
||||
raise osv.except_osv(
|
||||
_("Missing column !"),
|
||||
_("Column %s you try to import is not present in the bank statement line !") %(col))
|
||||
|
||||
statement_id = statement_obj.create(cursor,uid,{'profile_id':prof.id,},context)
|
||||
account_receivable, account_payable = statement_obj.get_default_pay_receiv_accounts(cursor, uid, context)
|
||||
_("Column %s you try to import is not "
|
||||
"present in the bank statement line !") % col)
|
||||
|
||||
statement_id = statement_obj.create(
|
||||
cr, uid, {'profile_id': prof.id}, context=context)
|
||||
account_receivable, account_payable = statement_obj.get_default_pay_receiv_accounts(
|
||||
cr, uid, context)
|
||||
try:
|
||||
# Record every line in the bank statement and compute the global commission
|
||||
# based on the commission_amount column
|
||||
for line in result_row_list:
|
||||
parser_vals = parser.get_st_line_vals(line)
|
||||
values = self.prepare_statetement_lines_vals(cursor, uid, parser_vals, account_payable,
|
||||
account_receivable, statement_id, context)
|
||||
values = self.prepare_statetement_lines_vals(
|
||||
cr, uid, parser_vals, account_payable,
|
||||
account_receivable, statement_id, context)
|
||||
# we finally create the line in system
|
||||
statement_line_obj.create(cursor, uid, values, context=context)
|
||||
statement_line_obj.create(cr, uid, values, context=context)
|
||||
# Build and create the global commission line for the whole statement
|
||||
comm_vals = self.prepare_global_commission_line_vals(cursor, uid, parser, result_row_list, prof, statement_id, context)
|
||||
comm_vals = self.prepare_global_commission_line_vals(
|
||||
cr, uid, parser, result_row_list, prof, statement_id, context)
|
||||
if comm_vals:
|
||||
res = statement_line_obj.create(cursor, uid, comm_vals,context=context)
|
||||
|
||||
statement_line_obj.create(cr, uid, comm_vals, context=context)
|
||||
|
||||
attachment_obj.create(
|
||||
cursor,
|
||||
cr,
|
||||
uid,
|
||||
{
|
||||
'name': 'statement file',
|
||||
'datas': file_stream,
|
||||
'datas_fname': "%s.%s"%(datetime.datetime.now().date(),
|
||||
ftype),
|
||||
'datas_fname': "%s.%s" % (
|
||||
datetime.datetime.now().date(),
|
||||
ftype),
|
||||
'res_model': 'account.bank.statement',
|
||||
'res_id': statement_id,
|
||||
},
|
||||
context=context
|
||||
)
|
||||
)
|
||||
# If user ask to launch completion at end of import, do it !
|
||||
if prof.launch_import_completion:
|
||||
statement_obj.button_auto_completion(cursor, uid, [statement_id], context)
|
||||
|
||||
statement_obj.button_auto_completion(cr, uid, [statement_id], context)
|
||||
|
||||
# Write the needed log infos on profile
|
||||
self.write_logs_after_import(cursor, uid, prof.id, statement_id,
|
||||
len(result_row_list), context)
|
||||
|
||||
except Exception, exc:
|
||||
statement_obj.unlink(cursor, uid, [statement_id])
|
||||
self.write_logs_after_import(
|
||||
cr, uid, prof.id, statement_id, len(result_row_list), context)
|
||||
|
||||
except Exception:
|
||||
statement_obj.unlink(cr, uid, [statement_id], context=context)
|
||||
error_type, error_value, trbk = sys.exc_info()
|
||||
st = "Error: %s\nDescription: %s\nTraceback:" % (error_type.__name__, error_value)
|
||||
st += ''.join(traceback.format_tb(trbk, 30))
|
||||
raise osv.except_osv(
|
||||
_("Statement import error"),
|
||||
_("The statement cannot be created : %s") %(st))
|
||||
_("The statement cannot be created : %s") % st)
|
||||
return statement_id
|
||||
|
||||
|
||||
|
||||
class AccountStatementLine(Model):
|
||||
@@ -228,8 +237,9 @@ class AccountStatementLine(Model):
|
||||
"""
|
||||
_inherit = "account.bank.statement.line"
|
||||
|
||||
_columns={
|
||||
'commission_amount': fields.sparse(type='float', string='Line Commission Amount',
|
||||
_columns = {
|
||||
'commission_amount': fields.sparse(
|
||||
type='float',
|
||||
string='Line Commission Amount',
|
||||
serialization_field='additionnal_bank_fields'),
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<field eval="20" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page/field[@name='line_ids']/form/field[@name='label']" position="after">
|
||||
<xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/form/group/field[@name='label']" position="after">
|
||||
<field name="commission_amount" />
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
@@ -23,15 +23,18 @@
|
||||
Wizard to import financial institute date in bank statement
|
||||
"""
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
from openerp.tools.translate import _
|
||||
import os
|
||||
|
||||
class CreditPartnerStatementImporter(osv.osv_memory):
|
||||
|
||||
class CreditPartnerStatementImporter(orm.TransientModel):
|
||||
_name = "credit.statement.import"
|
||||
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context is None: context = {}
|
||||
if context is None:
|
||||
context = {}
|
||||
res = {}
|
||||
if (context.get('active_model', False) == 'account.statement.profile' and
|
||||
context.get('active_ids', False)):
|
||||
@@ -39,80 +42,81 @@ class CreditPartnerStatementImporter(osv.osv_memory):
|
||||
assert len(ids) == 1, 'You cannot use this on more than one profile !'
|
||||
res['profile_id'] = ids[0]
|
||||
other_vals = self.onchange_profile_id(cr, uid, [], res['profile_id'], context=context)
|
||||
res.update(other_vals.get('value',{}))
|
||||
res.update(other_vals.get('value', {}))
|
||||
return res
|
||||
|
||||
|
||||
_columns = {
|
||||
'profile_id': fields.many2one('account.statement.profile',
|
||||
'Import configuration parameter',
|
||||
required=True),
|
||||
'input_statement': fields.binary('Statement file', required=True),
|
||||
'partner_id': fields.many2one('res.partner',
|
||||
'Credit insitute partner',
|
||||
),
|
||||
'Credit insitute partner'),
|
||||
'journal_id': fields.many2one('account.journal',
|
||||
'Financial journal to use transaction',
|
||||
),
|
||||
'input_statement': fields.binary('Statement file', required=True),
|
||||
'Financial journal to use transaction'),
|
||||
'file_name': fields.char('File Name', size=128),
|
||||
'commission_account_id': fields.many2one('account.account',
|
||||
'Commission account',
|
||||
),
|
||||
'Commission account'),
|
||||
'commission_analytic_id': fields.many2one('account.analytic.account',
|
||||
'Commission analytic account',
|
||||
),
|
||||
'Commission analytic account'),
|
||||
'receivable_account_id': fields.many2one('account.account',
|
||||
'Force Receivable/Payable Account'),
|
||||
'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 treasury/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."
|
||||
),
|
||||
}
|
||||
|
||||
'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 treasury/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."),
|
||||
}
|
||||
|
||||
def onchange_profile_id(self, cr, uid, ids, profile_id, context=None):
|
||||
res={}
|
||||
res = {}
|
||||
if profile_id:
|
||||
c = self.pool.get("account.statement.profile").browse(cr,uid,profile_id)
|
||||
res = {'value': {'partner_id': c.partner_id and c.partner_id.id or False,
|
||||
'journal_id': c.journal_id and c.journal_id.id or False, 'commission_account_id': \
|
||||
c.commission_account_id and c.commission_account_id.id or False,
|
||||
'receivable_account_id': c.receivable_account_id and c.receivable_account_id.id or False,
|
||||
'commission_a':c.commission_analytic_id and c.commission_analytic_id.id or False,
|
||||
'force_partner_on_bank':c.force_partner_on_bank,
|
||||
'balance_check':c.balance_check,}}
|
||||
c = self.pool.get("account.statement.profile").browse(
|
||||
cr, uid, profile_id, context=context)
|
||||
res = {'value':
|
||||
{'partner_id': c.partner_id and c.partner_id.id or False,
|
||||
'journal_id': c.journal_id and c.journal_id.id or False,
|
||||
'commission_account_id':
|
||||
c.commission_account_id and c.commission_account_id.id or False,
|
||||
'receivable_account_id': c.receivable_account_id and c.receivable_account_id.id or False,
|
||||
'commission_a': c.commission_analytic_id and c.commission_analytic_id.id or False,
|
||||
'force_partner_on_bank': c.force_partner_on_bank,
|
||||
'balance_check': c.balance_check,
|
||||
}
|
||||
}
|
||||
return res
|
||||
|
||||
def _check_extension(self, filename):
|
||||
(shortname, ftype) = os.path.splitext(filename)
|
||||
(__, ftype) = os.path.splitext(filename)
|
||||
if not ftype:
|
||||
#We do not use osv exception we do not want to have it logged
|
||||
raise Exception(_('Please use a file with an extention'))
|
||||
return ftype
|
||||
|
||||
def import_statement(self, cursor, uid, req_id, context=None):
|
||||
def import_statement(self, cr, uid, req_id, context=None):
|
||||
"""This Function import credit card agency statement"""
|
||||
context = context or {}
|
||||
if isinstance(req_id, list):
|
||||
req_id = req_id[0]
|
||||
importer = self.browse(cursor, uid, req_id, context)
|
||||
importer = self.browse(cr, uid, req_id, context)
|
||||
ftype = self._check_extension(importer.file_name)
|
||||
sid = self.pool.get(
|
||||
'account.statement.profile').statement_import(
|
||||
cursor,
|
||||
cr,
|
||||
uid,
|
||||
False,
|
||||
importer.profile_id.id,
|
||||
importer.input_statement,
|
||||
ftype.replace('.',''),
|
||||
ftype.replace('.', ''),
|
||||
context=context
|
||||
)
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
action_obj = self.pool.get('ir.actions.act_window')
|
||||
action_id = model_obj.get_object_reference(cursor, uid, 'account', 'action_bank_statement_tree')[1]
|
||||
res = action_obj.read(cursor, uid, action_id)
|
||||
action_id = model_obj.get_object_reference(cr, uid, 'account', 'action_bank_statement_tree')[1]
|
||||
res = action_obj.read(cr, uid, action_id)
|
||||
res['domain'] = res['domain'][:-1] + ",('id', '=', %d)]" % sid
|
||||
return res
|
||||
|
||||
@@ -18,4 +18,3 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account_statement_base_completion','account_voucher'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account_statement_base_completion',
|
||||
'account_voucher'
|
||||
],
|
||||
'description': """
|
||||
This module is only needed when using account_statement_base_completion with voucher in order adapt the view correctly.
|
||||
""",
|
||||
@@ -36,9 +39,9 @@
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
'installable': False,
|
||||
'images': [],
|
||||
'auto_install': True,
|
||||
'auto_install': False,
|
||||
'license': 'AGPL-3',
|
||||
'active': False,
|
||||
}
|
||||
|
||||
@@ -3,19 +3,19 @@
|
||||
<data>
|
||||
|
||||
<!-- Override what we have in account_statement_base_completion to replace the one in the voucher -->
|
||||
<record id="account_statement_base_completion.bank_statement_view_form2" model="ir.ui.view">
|
||||
<!-- <record id="account_statement_base_completion.bank_statement_view_form2" model="ir.ui.view">
|
||||
<field name="name">account_bank_statement_import_base.bank_statement.auto_cmpl</field>
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="inherit_id" ref="account_voucher.view_bank_statement_tree_voucher" />
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page/field[@name='line_ids']/tree/field[@name='voucher_id']" position="after">
|
||||
<xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/tree/field[@name='voucher_id']" position="after">
|
||||
<field name="already_completed" />
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</record> -->
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
|
||||
import statement
|
||||
import report
|
||||
import account
|
||||
import account
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account',
|
||||
'report_webkit'
|
||||
],
|
||||
'description': """
|
||||
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,
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
from openerp.osv.orm import Model, fields
|
||||
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
|
||||
|
||||
class account_move(Model):
|
||||
_inherit='account.move'
|
||||
|
||||
_inherit = 'account.move'
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Delete the reconciliation when we delete the moves. This
|
||||
@@ -35,6 +36,3 @@ class account_move(Model):
|
||||
if move_line.reconcile_id:
|
||||
move_line.reconcile_id.unlink(context=context)
|
||||
return super(account_move, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# __init__.py
|
||||
#
|
||||
# Copyright (c) 2009 CamptoCamp. All rights reserved.
|
||||
##############################################################################
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
@@ -28,4 +23,4 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import bank_statement_report
|
||||
import bank_statement_report
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Nicolas Bessi. Copyright Camptocamp SA
|
||||
@@ -18,33 +18,29 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from report import report_sxw
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
import pooler
|
||||
from operator import add, itemgetter
|
||||
from itertools import groupby
|
||||
from openerp.report import report_sxw
|
||||
from openerp.tools.translate import _
|
||||
from openerp import pooler
|
||||
from datetime import datetime
|
||||
from report_webkit import webkit_report
|
||||
|
||||
|
||||
class BankStatementWebkit(report_sxw.rml_parse):
|
||||
|
||||
def __init__(self, cursor, uid, name, context):
|
||||
super(BankStatementWebkit, self).__init__(cursor, uid, name, context=context)
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(BankStatementWebkit, self).__init__(cr, uid, name, context=context)
|
||||
self.pool = pooler.get_pool(self.cr.dbname)
|
||||
self.cursor = self.cr
|
||||
|
||||
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
|
||||
company = self.pool.get('res.users').browse(
|
||||
self.cr, uid, uid, context=context).company_id
|
||||
header_report_name = ' - '.join((_('BORDEREAU DE REMISE DE CHEQUES'),
|
||||
company.name, company.currency_id.name))
|
||||
statement = self.pool.get('account.bank.statement').browse(cursor,uid,context['active_id']);
|
||||
footer_date_time = self.formatLang(str(datetime.today())[:19], date_time=True)
|
||||
self.localcontext.update({
|
||||
'cr': cursor,
|
||||
'cr': cr,
|
||||
'uid': uid,
|
||||
'get_bank_statement' : self._get_bank_statement_data,
|
||||
'get_bank_statement': self._get_bank_statement_data,
|
||||
'report_name': _('BORDEREAU DE REMISE DE CHEQUES'),
|
||||
'additional_args': [
|
||||
('--header-font-name', 'Helvetica'),
|
||||
@@ -58,10 +54,15 @@ class BankStatementWebkit(report_sxw.rml_parse):
|
||||
('--footer-line',),
|
||||
],
|
||||
})
|
||||
def _get_bank_statement_data(self,statement):
|
||||
|
||||
def _get_bank_statement_data(self, statement):
|
||||
statement_obj = self.pool.get('account.bank.statement.line')
|
||||
statement_line_ids = statement_obj.search(self.cr,self.uid,[['statement_id','=',statement.id]])
|
||||
statement_lines = statement_obj.browse(self.cr,self.uid,statement_line_ids)
|
||||
statement_line_ids = statement_obj.search(
|
||||
self.cr,
|
||||
self.uid,
|
||||
[('statement_id', '=', statement.id)])
|
||||
statement_lines = statement_obj.browse(
|
||||
self.cr, self.uid, statement_line_ids)
|
||||
return statement_lines
|
||||
|
||||
webkit_report.WebKitParser('report.bank_statement_webkit',
|
||||
|
||||
@@ -19,12 +19,10 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from tools.translate import _
|
||||
import datetime
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class AccountStatementProfil(Model):
|
||||
"""
|
||||
@@ -34,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
|
||||
|
||||
@@ -83,65 +89,73 @@ 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):
|
||||
|
||||
def _get_period(self, cr, uid, date, context=None):
|
||||
"""
|
||||
Find matching period for date, used in the statement line creation.
|
||||
"""
|
||||
period_obj = self.pool.get('account.period')
|
||||
periods = period_obj.find(cursor, uid, dt=date, context=context)
|
||||
periods = period_obj.find(cr, 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
|
||||
@@ -158,175 +172,117 @@ 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)
|
||||
move.unlink(context=context)
|
||||
done.append(st.id)
|
||||
self.write(cr, uid, done, {'state':'draft'}, context=context)
|
||||
return True
|
||||
return super(AccountBankSatement, self).button_cancel(
|
||||
cr, uid, ids, context=context)
|
||||
|
||||
def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None):
|
||||
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.
|
||||
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 char st_line_number: will be used as the name of the generated account move
|
||||
:return: dict of value to create() the account.move
|
||||
"""
|
||||
if context is None:
|
||||
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):
|
||||
"""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
|
||||
:param float debit: debit amount of the move line
|
||||
:param float credit: credit amount of the move line
|
||||
:param int/long currency_id: ID of currency of the move line to create
|
||||
:param float amount_currency: amount of the debit/credit expressed in the currency_id
|
||||
:param int/long account_id: ID of the account to use in the move line if different
|
||||
from the statement line account ID
|
||||
:param int/long analytic_id: ID of analytic account to put on the move line
|
||||
:param int/long partner_id: ID of the partner to put on the move line
|
||||
:return: dict of value to create() the account.move.line
|
||||
"""
|
||||
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)
|
||||
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 _get_counter_part_partner(self, cr, uid, st_line, context=None):
|
||||
"""
|
||||
Override a large portion of the code to compute the periode for each line instead of
|
||||
taking the period of the whole statement.
|
||||
Remove the entry posting on generated account moves.
|
||||
We change the move line generated from the lines depending on the profile:
|
||||
- If receivable_account_id is set, we'll use it instead of the "partner" one
|
||||
- If partner_id is set, we'll us it for the commission (when imported throufh the wizard)
|
||||
- If partner_id is set and force_partner_on_bank is ticked, we'll let the partner of each line
|
||||
for the debit line, but we'll change it on the credit move line for the choosen partner_id
|
||||
=> This will ease the reconciliation process with the bank as the partner will match the bank
|
||||
statement line
|
||||
|
||||
:param int/long: st_line_id: account.bank.statement.line ID
|
||||
:param int/long: company_currency_id: res.currency ID
|
||||
:param char: st_line_number: that will be used as the name of the generated account move
|
||||
:return: int/long: ID of the created account.move
|
||||
:param browse_record st_line: account.bank.statement.line record to
|
||||
create the move from.
|
||||
:return: int/long of the res.partner to use as counterpart
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res_currency_obj = self.pool.get('res.currency')
|
||||
account_move_obj = self.pool.get('account.move')
|
||||
account_move_line_obj = self.pool.get('account.move.line')
|
||||
account_bank_statement_line_obj = self.pool.get('account.bank.statement.line') # Chg
|
||||
st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context) # Chg
|
||||
st = st_line.statement_id
|
||||
|
||||
context.update({'date': st_line.date})
|
||||
ctx = context.copy() # Chg
|
||||
ctx['company_id'] = st_line.company_id.id # Chg
|
||||
period_id = self._get_period( # Chg
|
||||
cr, uid, st_line.date, context=ctx)
|
||||
|
||||
move_id = account_move_obj.create(cr, uid, {
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': period_id, # Chg
|
||||
'date': st_line.date,
|
||||
'name': st_line_number,
|
||||
'ref': st_line.ref,
|
||||
}, context=context)
|
||||
account_bank_statement_line_obj.write(cr, uid, [st_line.id], { # Chg
|
||||
'move_ids': [(4, move_id, False)]
|
||||
})
|
||||
|
||||
torec = []
|
||||
if st_line.amount >= 0:
|
||||
account_id = st.journal_id.default_credit_account_id.id
|
||||
else:
|
||||
account_id = st.journal_id.default_debit_account_id.id
|
||||
|
||||
acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id
|
||||
context.update({
|
||||
'res.currency.compute.account': acc_cur,
|
||||
})
|
||||
amount = res_currency_obj.compute(cr, uid, st.currency.id,
|
||||
company_currency_id, st_line.amount, context=context)
|
||||
|
||||
val = {
|
||||
'name': st_line.name,
|
||||
'date': st_line.date,
|
||||
'ref': st_line.ref,
|
||||
'move_id': move_id,
|
||||
'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False,
|
||||
'account_id': (st_line.account_id) and st_line.account_id.id,
|
||||
'credit': ((amount>0) and amount) or 0.0,
|
||||
'debit': ((amount<0) and -amount) or 0.0,
|
||||
# Replace with the treasury one instead of bank #Chg
|
||||
'statement_id': st.id,
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': period_id, #Chg
|
||||
'currency_id': st.currency.id,
|
||||
'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False
|
||||
}
|
||||
|
||||
if st.currency.id <> company_currency_id:
|
||||
amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
|
||||
st.currency.id, amount, context=context)
|
||||
val['amount_currency'] = -amount_cur
|
||||
|
||||
if st_line.account_id and st_line.account_id.currency_id and st_line.account_id.currency_id.id <> company_currency_id:
|
||||
val['currency_id'] = st_line.account_id.currency_id.id
|
||||
amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
|
||||
st_line.account_id.currency_id.id, amount, context=context)
|
||||
val['amount_currency'] = -amount_cur
|
||||
|
||||
move_line_id = account_move_line_obj.create(cr, uid, val, context=context)
|
||||
torec.append(move_line_id)
|
||||
|
||||
# Fill the secondary amount/currency
|
||||
# if currency is not the same than the company
|
||||
amount_currency = False
|
||||
currency_id = False
|
||||
if st.currency.id <> company_currency_id:
|
||||
amount_currency = st_line.amount
|
||||
currency_id = st.currency.id
|
||||
# GET THE RIGHT PARTNER ACCORDING TO THE CHOSEN PROFIL # Chg
|
||||
if st.profile_id.force_partner_on_bank: # Chg
|
||||
bank_parrtner_id = st.profile_id.partner_id.id # Chg
|
||||
else: # Chg
|
||||
bank_parrtner_id = ((st_line.partner_id) and st_line.partner_id.id) or False # Chg
|
||||
|
||||
account_move_line_obj.create(cr, uid, {
|
||||
'name': st_line.name,
|
||||
'date': st_line.date,
|
||||
'ref': st_line.ref,
|
||||
'move_id': move_id,
|
||||
'partner_id': bank_parrtner_id, # Chg
|
||||
'account_id': account_id,
|
||||
'credit': ((amount < 0) and -amount) or 0.0,
|
||||
'debit': ((amount > 0) and amount) or 0.0,
|
||||
# Replace with the treasury one instead of bank #Chg
|
||||
'statement_id': st.id,
|
||||
'journal_id': st.journal_id.id,
|
||||
'period_id': period_id, #Chg
|
||||
'amount_currency': amount_currency,
|
||||
'currency_id': currency_id,
|
||||
}, context=context)
|
||||
|
||||
for line in account_move_line_obj.browse(cr, uid, [x.id for x in
|
||||
account_move_obj.browse(cr, uid, move_id,
|
||||
context=context).line_id],
|
||||
context=context):
|
||||
if line.state <> 'valid':
|
||||
raise osv.except_osv(_('Error !'),
|
||||
_('Journal item "%s" is not valid.') % line.name)
|
||||
|
||||
# Bank statements will not consider boolean on journal entry_posted
|
||||
account_move_obj.post(cr, uid, [move_id], context=context)
|
||||
return move_id
|
||||
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:
|
||||
@@ -342,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):
|
||||
@@ -364,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
|
||||
@@ -397,19 +350,19 @@ class AccountBankSatement(Model):
|
||||
'name': st_number,
|
||||
'balance_end_real': st.balance_end
|
||||
}, context=context)
|
||||
self.log(cr, uid, st.id, _('Statement %s is confirmed, journal items are created.') % (st_number,))
|
||||
return self.write(cr, uid, ids, {'state':'confirm'}, 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)
|
||||
|
||||
def get_account_for_counterpart(self, cursor, uid,
|
||||
amount, account_receivable, account_payable):
|
||||
def get_account_for_counterpart(
|
||||
self, cr, 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.
|
||||
"""
|
||||
@@ -425,40 +378,39 @@ class AccountBankSatement(Model):
|
||||
)
|
||||
return account_id
|
||||
|
||||
def get_default_pay_receiv_accounts(self, cursor, uid, context=None):
|
||||
def get_default_pay_receiv_accounts(self, cr, 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(
|
||||
cursor,
|
||||
cr,
|
||||
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),
|
||||
],
|
||||
cr,
|
||||
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(
|
||||
cr, 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':
|
||||
@@ -469,56 +421,61 @@ 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"
|
||||
|
||||
def _get_period(self, cursor, user, context=None):
|
||||
def _get_period(self, cr, uid, context=None):
|
||||
"""
|
||||
Return a period from a given date in the context.
|
||||
"""
|
||||
date = context.get('date', None)
|
||||
periods = self.pool.get('account.period').find(cursor, user, dt=date)
|
||||
periods = self.pool.get('account.period').find(cr, uid, dt=date)
|
||||
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']
|
||||
|
||||
def _get_default_account(self, cr, uid, context=None):
|
||||
return self.get_values_for_line(cr, uid, context=context)['account_id']
|
||||
|
||||
_columns = {
|
||||
# Set them as required + 64 char instead of 32
|
||||
'ref': fields.char('Reference', size=64, required=True),
|
||||
@@ -528,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
|
||||
@@ -540,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'
|
||||
@@ -553,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
|
||||
@@ -573,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:
|
||||
@@ -589,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)
|
||||
@@ -613,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
|
||||
|
||||
|
||||
@@ -73,32 +73,20 @@
|
||||
|
||||
<menuitem string="Bank Statements Profile" action="action_treasury_statement_profile_tree" id="menu_treasury_statement_profile_tree" parent="account.menu_configuration_misc" sequence="30"/>
|
||||
|
||||
<record model="ir.ui.view" id="id_in_statement_line">
|
||||
<field name="name">account.bank.statement.line.inherit</field>
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="inherit_id" ref="account.view_bank_statement_periodic_form"/>
|
||||
<field name="priority" eval="30"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/notebook/page[@string='Journal Entries']/field/tree/field[@name='ref']" position="before">
|
||||
<field name="id" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_treasury_statement_search" model="ir.ui.view">
|
||||
<field name="name">account.bank.statement.search</field>
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="inherit_id" ref="account.view_bank_statement_search"/>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/search/group/field[@name='name']" position="before">
|
||||
<xpath expr="/search/field[@name='name']" position="before">
|
||||
<field name="id"/>
|
||||
<field name="profile_id"/>
|
||||
<field name="credit_partner_id"/>
|
||||
<separator orientation="vertical"/>
|
||||
</xpath>
|
||||
<xpath expr="/search/group/field[@name='period_id']" position="replace">
|
||||
<xpath expr="/search/field[@name='period_id']" position="replace">
|
||||
</xpath>
|
||||
<xpath expr="/search/group/filter[@string='Period']" position="replace">
|
||||
<filter string="Financial Partner" context="{'group_by': 'credit_partner_id'}" icon="terp-partner"/>
|
||||
@@ -124,76 +112,64 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_treasury_statement_form" model="ir.ui.view">
|
||||
<field name="name">account.bank.statement.form</field>
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="inherit_id" ref="account.view_bank_statement_form"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<!-- Remove name and date from group tag -->
|
||||
<xpath expr="/form/group/field[@name='name']" position="replace">
|
||||
</xpath>
|
||||
<xpath expr="/form/group/field[@name='date']" position="replace">
|
||||
</xpath>
|
||||
<!-- Add a new group before the first one with name, profile and date -->
|
||||
<xpath expr="/form/group[@col='7']" position="before">
|
||||
<group col="8" colspan="4">
|
||||
<field name="profile_id" select="1" required="1" on_change="onchange_imp_config_id(profile_id)" widget="selection"/>
|
||||
<field name="date" select="1" on_change="onchange_date(date, company_id)"/>
|
||||
<field name="name" select="1"/>
|
||||
</group>
|
||||
<separator string="Profile Details" colspan="4"/>
|
||||
</xpath>
|
||||
<!-- Make balance visible or not depending on profile -->
|
||||
<xpath expr="/form/group/field[@name='balance_start']" position="replace">
|
||||
</xpath>
|
||||
<xpath expr="/form/group/field[@name='balance_end_real']" position="replace">
|
||||
</xpath>
|
||||
<xpath expr="/form/group[@col='7']" position="after">
|
||||
<separator string="Balance Check" colspan="4" attrs="{'invisible':[('balance_check','=',False)]}"/>
|
||||
<group col="6" colspan="4" attrs="{'invisible':[('balance_check','=',False)]}">
|
||||
<field name="balance_start" />
|
||||
<field name="balance_end_real" />
|
||||
</group>
|
||||
</xpath>
|
||||
<xpath expr="/form/group/field[@name='balance_end']" position="replace">
|
||||
<field name="balance_end"/>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/group/field[@name='journal_id']" position="attributes">
|
||||
<attribute name="widget"></attribute>
|
||||
</xpath>
|
||||
<xpath expr="/form/group/field[@name='period_id']" position="replace">
|
||||
<field name="credit_partner_id"/>
|
||||
<field name="account_id" invisible="1"/>
|
||||
<field name="balance_check" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/tree/field[@name='sequence']" position="after">
|
||||
<field name="id"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/tree/field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,parent.profile_id)"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/form/field[@name='date']" position="before">
|
||||
<field name="id"/>
|
||||
</xpath>
|
||||
<!-- Adapt onchange signature -->
|
||||
<xpath expr="/form/notebook/page/field/tree/field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,parent.profile_id)"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/form/field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,parent.profile_id)"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/form/field[@name='type']" position="replace">
|
||||
<field name="type" on_change="onchange_type(partner_id, type, parent.profile_id)"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field/tree/field[@name='type']" position="replace">
|
||||
<field name="type" on_change="onchange_type(partner_id, type, parent.profile_id)"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_treasury_statement_form" model="ir.ui.view">
|
||||
<field name="name">account.bank.statement.form</field>
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="inherit_id" ref="account.view_bank_statement_form"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
|
||||
<!-- Add before the group : profile and related infos -->
|
||||
<xpath expr="/form/sheet/group/group/field[@name='journal_id']" position="replace">
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/sheet/group" position="after">
|
||||
<group>
|
||||
<field name="profile_id" select="1" required="1" on_change="onchange_imp_config_id(profile_id)" widget="selection"/>
|
||||
<separator string="Profile Details" colspan="4"/>
|
||||
<field name="journal_id" domain="[('type', '=', 'bank')]" on_change="onchange_journal_id(journal_id)" widget="selection"/>
|
||||
<field name="credit_partner_id"/>
|
||||
<field name="account_id" invisible="1"/>
|
||||
<field name="balance_check" invisible="1"/>
|
||||
</group>
|
||||
</xpath>
|
||||
|
||||
# Make balance visible or not depending on profile
|
||||
<xpath expr="/form/sheet/group/group/field[@name='balance_start']" position="attributes">
|
||||
<attribute name="attrs">{'invisible':[('balance_check','=',False)]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="/form/sheet/group/group/field[@name='balance_end_real']" position="attributes">
|
||||
<attribute name="attrs">{'invisible':[('balance_check','=',False)]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="/form/sheet/group/group/field[@name='balance_end_real']" position="after">
|
||||
<field name="balance_end" widget="monetary" options='{"currency_field" : "currency"}'/>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/sheet/notebook/page/field/tree/field[@name='sequence']" position="after">
|
||||
<field name="id" readonly="1" />
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/sheet/notebook/page/field/form/group/field[@name='date']" position="before">
|
||||
<field name="id" readonly="1" />
|
||||
</xpath>
|
||||
# Adapt onchange signature
|
||||
<xpath expr="/form/sheet/notebook/page/field/tree/field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,parent.profile_id)" domain="['|',('parent_id','=',False),('is_company','=',True)]"/>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="/form/sheet/notebook/page/field/form/group/field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id,parent.profile_id)" domain="['|',('parent_id','=',False),('is_company','=',True)]"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/sheet/notebook/page/field/form/group/field[@name='type']" position="replace">
|
||||
<field name="type" on_change="onchange_type(partner_id, type, parent.profile_id)"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/sheet/notebook/page/field/tree/field[@name='type']" position="replace">
|
||||
<field name="type" on_change="onchange_type(partner_id, type, parent.profile_id)"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<act_window id="act_bank_statement_from_profile"
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account_statement_ext','account_voucher'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account_statement_ext',
|
||||
'account_voucher'
|
||||
],
|
||||
'description': """
|
||||
This module is only needed when using account_bank_statement_ext with voucher in order to compute the period
|
||||
correctly. This is mainly because with account_bank_statement_ext, the period is computed for each line.
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv.orm import Model, fields
|
||||
|
||||
from openerp.osv.orm import Model
|
||||
|
||||
|
||||
class AccountVoucher(Model):
|
||||
@@ -30,7 +31,8 @@ class AccountVoucher(Model):
|
||||
if context is None:
|
||||
context = {}
|
||||
if not context.get('period_id') and context.get('move_line_ids'):
|
||||
res = self.pool.get('account.move.line').browse(cr, uid , context.get('move_line_ids'))[0].period_id.id
|
||||
res = self.pool.get('account.move.line').browse(
|
||||
cr, uid, context.get('move_line_ids'), context=context)[0].period_id.id
|
||||
context['period_id'] = res
|
||||
elif context.get('date'):
|
||||
periods = self.pool.get('account.period').find(
|
||||
@@ -47,4 +49,3 @@ class AccountVoucher(Model):
|
||||
ctx = dict(context, date=values.get('date'))
|
||||
values['period_id'] = self._get_period(cr, uid, ctx)
|
||||
return super(AccountVoucher, self).create(cr, uid, values, context)
|
||||
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account_statement_base_completion', 'base_transaction_id'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account_statement_base_completion',
|
||||
'base_transaction_id'
|
||||
],
|
||||
'description': """
|
||||
Add a completion method based on transaction ID providen by the bank/office.
|
||||
|
||||
|
||||
@@ -19,28 +19,28 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from tools.translate import _
|
||||
import datetime
|
||||
import netsvc
|
||||
logger = netsvc.Logger()
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner
|
||||
|
||||
|
||||
class AccountStatementCompletionRule(Model):
|
||||
"""Add a rule based on transaction ID"""
|
||||
|
||||
|
||||
_inherit = "account.statement.completion.rule"
|
||||
|
||||
|
||||
def _get_functions(self, cr, uid, context=None):
|
||||
res = super (AccountStatementCompletionRule, self)._get_functions(
|
||||
res = super(AccountStatementCompletionRule, self)._get_functions(
|
||||
cr, uid, context=context)
|
||||
res.append(('get_from_transaction_id_and_so', 'From line reference (based on SO transaction ID)'))
|
||||
res.append(('get_from_transaction_id_and_so',
|
||||
'From line reference (based on SO transaction ID)'))
|
||||
return res
|
||||
|
||||
_columns={
|
||||
_columns = {
|
||||
'function_to_call': fields.selection(_get_functions, 'Method'),
|
||||
}
|
||||
|
||||
|
||||
def get_from_transaction_id_and_so(self, cr, uid, line_id, context=None):
|
||||
"""
|
||||
Match the partner based on the transaction ID field of the SO.
|
||||
@@ -55,36 +55,45 @@ class AccountStatementCompletionRule(Model):
|
||||
...}
|
||||
"""
|
||||
st_obj = self.pool.get('account.bank.statement.line')
|
||||
st_line = st_obj.browse(cr,uid,line_id)
|
||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||
res = {}
|
||||
if st_line:
|
||||
so_obj = self.pool.get('sale.order')
|
||||
so_id = so_obj.search(cr, uid, [('transaction_id', '=', st_line.transaction_id)])
|
||||
so_id = so_obj.search(
|
||||
cr,
|
||||
uid,
|
||||
[('transaction_id', '=', st_line.transaction_id)],
|
||||
context=context)
|
||||
if so_id and len(so_id) == 1:
|
||||
so = so_obj.browse(cr, uid, so_id[0])
|
||||
so = so_obj.browse(cr, uid, so_id[0], context=context)
|
||||
res['partner_id'] = so.partner_id.id
|
||||
res['ref'] = so.name
|
||||
elif so_id and len(so_id) > 1:
|
||||
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than one partner.')%(st_line.name,st_line.ref))
|
||||
raise ErrorTooManyPartner(
|
||||
_('Line named "%s" (Ref:%s) was matched by more than '
|
||||
'one partner.') % (st_line.name, st_line.ref))
|
||||
if so_id:
|
||||
st_vals = st_obj.get_values_for_line(cr, uid, profile_id = st_line.statement_id.profile_id.id,
|
||||
partner_id = res.get('partner_id',False), line_type = st_line.type, amount = st_line.amount, context=context)
|
||||
st_vals = st_obj.get_values_for_line(
|
||||
cr,
|
||||
uid,
|
||||
profile_id=st_line.statement_id.profile_id.id,
|
||||
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):
|
||||
_inherit = "account.bank.statement.line"
|
||||
|
||||
_columns={
|
||||
_columns = {
|
||||
# 'additionnal_bank_fields' : fields.serialized('Additionnal infos from bank', help="Used by completion and import system."),
|
||||
'transaction_id': fields.sparse(type='char', string='Transaction ID',
|
||||
'transaction_id': fields.sparse(
|
||||
type='char',
|
||||
string='Transaction ID',
|
||||
size=128,
|
||||
serialization_field='additionnal_bank_fields',
|
||||
help="Transction id from the financial institute"),
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page/field[@name='line_ids']/form/field[@name='label']" position="after">
|
||||
<xpath expr="/form/sheet/notebook/page/field[@name='line_ids']/form/group/field[@name='label']" position="after">
|
||||
<field name="transaction_id" />
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
@@ -19,4 +19,4 @@
|
||||
#
|
||||
##############################################################################
|
||||
import parser
|
||||
import statement
|
||||
import statement
|
||||
|
||||
@@ -24,8 +24,11 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal', #easy, normal, expert
|
||||
'depends': ['account_statement_base_import','account_statement_transactionid_completion'],
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account_statement_base_import',
|
||||
'account_statement_transactionid_completion'
|
||||
],
|
||||
'description': """
|
||||
This module brings generic methods and fields on bank statement to deal with
|
||||
the importation of different bank and offices that uses transactionID.
|
||||
@@ -36,12 +39,12 @@
|
||||
|
||||
This module can handle a commission taken by the payment office and has the following format:
|
||||
|
||||
* transaction_id : the transaction ID given by the bank/office. It is used as reference
|
||||
* transaction_id: the transaction ID given by the bank/office. It is used as reference
|
||||
in the generated entries and is useful for reconciliation process
|
||||
* date : date of the payment
|
||||
* amount : amount paid in the currency of the journal used in the importation profile
|
||||
* commission_amount : amount of the comission for each line
|
||||
* label : the comunication given by the payment office, used as communication in the
|
||||
* date: date of the payment
|
||||
* amount: amount paid in the currency of the journal used in the importation profile
|
||||
* commission_amount: amount of the comission for each line
|
||||
* label: the comunication given by the payment office, used as communication in the
|
||||
generated entries.
|
||||
""",
|
||||
'website': 'http://www.camptocamp.com',
|
||||
|
||||
@@ -19,6 +19,4 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# from parser import new_bank_statement_parser
|
||||
# from parser import BankStatementImportParser
|
||||
import transactionid_file_parser
|
||||
import transactionid_file_parser
|
||||
|
||||
@@ -19,23 +19,16 @@
|
||||
##############################################################################
|
||||
|
||||
from openerp.tools.translate import _
|
||||
import base64
|
||||
import csv
|
||||
import tempfile
|
||||
import datetime
|
||||
from account_statement_base_import.parser.file_parser import FileParser
|
||||
|
||||
try:
|
||||
import xlrd
|
||||
except:
|
||||
raise Exception(_('Please install python lib xlrd'))
|
||||
|
||||
class TransactionIDFileParser(FileParser):
|
||||
"""
|
||||
TransactionID parser that use a define format in csv or xls to import
|
||||
bank statement.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parse_name, ftype='csv'):
|
||||
convertion_dict = {
|
||||
'transaction_id': unicode,
|
||||
@@ -46,7 +39,7 @@ class TransactionIDFileParser(FileParser):
|
||||
}
|
||||
# Order of cols does not matter but first row of the file has to be header
|
||||
keys_to_validate = ['transaction_id', 'label', 'date', 'amount', 'commission_amount']
|
||||
super(TransactionIDFileParser,self).__init__(parse_name, keys_to_validate=keys_to_validate, ftype=ftype, convertion_dict=convertion_dict)
|
||||
super(TransactionIDFileParser, self).__init__(parse_name, keys_to_validate=keys_to_validate, ftype=ftype, convertion_dict=convertion_dict)
|
||||
|
||||
@classmethod
|
||||
def parser_for(cls, parser_name):
|
||||
@@ -59,7 +52,7 @@ class TransactionIDFileParser(FileParser):
|
||||
def get_st_line_vals(self, line, *args, **kwargs):
|
||||
"""
|
||||
This method must return a dict of vals that can be passed to create
|
||||
method of statement line in order to record it. It is the responsibility
|
||||
method of statement line in order to record it. It is the responsibility
|
||||
of every parser to give this dict of vals, so each one can implement his
|
||||
own way of recording the lines.
|
||||
:param: line: a dict of vals that represent a line of result_row_list
|
||||
@@ -77,12 +70,12 @@ class TransactionIDFileParser(FileParser):
|
||||
for each one.
|
||||
"""
|
||||
return {
|
||||
'name': line.get('label', line.get('ref','/')),
|
||||
'name': line.get('label', line.get('ref', '/')),
|
||||
'date': line.get('date', datetime.datetime.now().date()),
|
||||
'amount': line.get('amount', 0.0),
|
||||
'ref': line.get('transaction_id','/'),
|
||||
'label': line.get('label',''),
|
||||
'transaction_id': line.get('transaction_id','/'),
|
||||
'ref': line.get('transaction_id', '/'),
|
||||
'label': line.get('label', ''),
|
||||
'transaction_id': line.get('transaction_id', '/'),
|
||||
'commission_amount': line.get('commission_amount', 0.0),
|
||||
}
|
||||
|
||||
@@ -93,7 +86,6 @@ class TransactionIDFileParser(FileParser):
|
||||
res = super(TransactionIDFileParser, self)._post(*args, **kwargs)
|
||||
val = 0.0
|
||||
for row in self.result_row_list:
|
||||
val += row.get('commission_amount',0.0)
|
||||
val += row.get('commission_amount', 0.0)
|
||||
self.commission_global_amount = val
|
||||
return res
|
||||
|
||||
|
||||
@@ -19,25 +19,29 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import Model, fields
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
|
||||
|
||||
class AccountStatementProfil(Model):
|
||||
_inherit = "account.statement.profile"
|
||||
|
||||
|
||||
|
||||
def get_import_type_selection(self, cr, uid, context=None):
|
||||
"""
|
||||
Has to be inherited to add parser
|
||||
"""
|
||||
res = super(AccountStatementProfil, self).get_import_type_selection(cr, uid, context=context)
|
||||
res.append(('generic_csvxls_transaction','Generic .csv/.xls based on SO transaction ID'))
|
||||
res = super(AccountStatementProfil, self).get_import_type_selection(
|
||||
cr, uid, context=context)
|
||||
res.append(('generic_csvxls_transaction',
|
||||
'Generic .csv/.xls based on SO transaction ID'))
|
||||
return res
|
||||
|
||||
|
||||
|
||||
_columns = {
|
||||
'import_type': fields.selection(get_import_type_selection, 'Type of import', required=True,
|
||||
help = "Choose here the method by which you want to import bank statement for this profile."),
|
||||
|
||||
'import_type': fields.selection(
|
||||
get_import_type_selection,
|
||||
'Type of import',
|
||||
required=True,
|
||||
help="Choose here the method by which you want to import "
|
||||
"bank statement for this profile."),
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,18 +24,30 @@
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Hidden/Dependency',
|
||||
'complexity': 'easy', #easy, normal, expert
|
||||
'depends': ['account', 'sale','stock'],
|
||||
'complexity': 'easy',
|
||||
'depends': [
|
||||
'account',
|
||||
'sale',
|
||||
'stock'
|
||||
],
|
||||
'description': """
|
||||
Adds transaction id to invoice and sale models and views. On Sales order, you can specify the transaction ID
|
||||
used for the payment and it will be propagated to the invoice (even if made from packing).
|
||||
This is mostly used for e-commerce handling. You can then add a mapping on that SO field to save the e-commerce
|
||||
financial Transaction ID into the OpenERP SO field. The main purpose is to ease the reconciliation process and
|
||||
Adds transaction id to invoice and sale models and views.
|
||||
On Sales order, you can specify the transaction ID used
|
||||
for the payment and it will be propagated to the invoice
|
||||
(even if made from packing).
|
||||
This is mostly used for e-commerce handling.
|
||||
You can then add a mapping on that SO field to save
|
||||
the e-commerce financial Transaction ID into the
|
||||
OpenERP sale order field.
|
||||
The main purpose is to ease the reconciliation process and
|
||||
be able to find the partner when importing the bank statement.
|
||||
""",
|
||||
'website': 'http://www.openerp.com',
|
||||
'init_xml': [],
|
||||
'update_xml': ['invoice_view.xml', 'sale_view.xml'],
|
||||
'update_xml': [
|
||||
'invoice_view.xml',
|
||||
'sale_view.xml'
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
|
||||
@@ -19,17 +19,18 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
|
||||
class AccountInvoice(osv.osv):
|
||||
|
||||
class AccountInvoice(Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
_columns = {
|
||||
'transaction_id':fields.char(
|
||||
'transaction_id': fields.char(
|
||||
'Transaction id',
|
||||
size=128,
|
||||
required=False,
|
||||
select=1,
|
||||
help="Transction id from the financial institute"
|
||||
),
|
||||
help="Transction id from the financial institute"),
|
||||
}
|
||||
|
||||
@@ -19,21 +19,25 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
|
||||
class SaleOrder(osv.osv):
|
||||
|
||||
class SaleOrder(Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
_columns = {
|
||||
'transaction_id':fields.char('Transaction id', size=128,required=False,
|
||||
help="Transction id from the financial institute"),
|
||||
'transaction_id': fields.char(
|
||||
'Transaction id',
|
||||
size=128,
|
||||
required=False,
|
||||
help="Transaction id from the financial institute"),
|
||||
}
|
||||
|
||||
|
||||
def _prepare_invoice(self, cursor, uid, order, lines, context=None):
|
||||
def _prepare_invoice(self, cr, uid, order, lines, context=None):
|
||||
#we put the transaction id in the generated invoices
|
||||
if context is None:
|
||||
context = {}
|
||||
invoice_vals = super(SaleOrder, self)._prepare_invoice(cursor, uid, order, lines, context)
|
||||
invoice_vals = super(SaleOrder, self)._prepare_invoice(
|
||||
cr, uid, order, lines, context=context)
|
||||
invoice_vals.update({
|
||||
'transaction_id': order.transaction_id})
|
||||
return invoice_vals
|
||||
|
||||
@@ -19,20 +19,24 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv
|
||||
from openerp.osv.orm import Model
|
||||
|
||||
class StockPicking(osv.osv):
|
||||
|
||||
class StockPicking(Model):
|
||||
_inherit = "stock.picking"
|
||||
|
||||
def action_invoice_create(self, cursor, uid, ids, journal_id=False,
|
||||
group=False, type='out_invoice', context=None):
|
||||
res = super(StockPicking, self).action_invoice_create(cursor, uid, ids,
|
||||
journal_id,group, type, context)
|
||||
def action_invoice_create(
|
||||
self, cr, uid, ids, journal_id=False, group=False,
|
||||
type='out_invoice', context=None):
|
||||
res = super(StockPicking, self).action_invoice_create(
|
||||
cr, uid, ids, journal_id, group, type, context)
|
||||
for pick_id in res:
|
||||
pick = self.browse(cursor, uid, pick_id)
|
||||
pick = self.browse(cr, uid, pick_id, context=context)
|
||||
if pick.sale_id and pick.sale_id.transaction_id:
|
||||
self.pool.get('account.invoice').write(cursor,
|
||||
uid,
|
||||
res[pick_id],
|
||||
{'transaction_id': pick.sale_id.transaction_id})
|
||||
self.pool.get('account.invoice').write(
|
||||
cr,
|
||||
uid,
|
||||
res[pick_id],
|
||||
{'transaction_id': pick.sale_id.transaction_id},
|
||||
context=context)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user