mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[IMP] account_statement_base_completion: Method get_st_vals in the same line of get_st_line_vals.
This commit is contained in:
@@ -184,7 +184,7 @@ class AccountStatementCompletionRule(orm.Model):
|
|||||||
inv = self._find_invoice(cr, uid, line, inv_type, context=context)
|
inv = self._find_invoice(cr, uid, line, inv_type, context=context)
|
||||||
if inv:
|
if inv:
|
||||||
# FIXME use only commercial_partner_id of invoice in 7.1
|
# FIXME use only commercial_partner_id of invoice in 7.1
|
||||||
# this is for backward compatibility in 7.0 before
|
# this is for backward compatibility in 7.0 before
|
||||||
# the refactoring of res.partner
|
# the refactoring of res.partner
|
||||||
if hasattr(inv, 'commercial_partner_id'):
|
if hasattr(inv, 'commercial_partner_id'):
|
||||||
partner_id = inv.commercial_partner_id.id
|
partner_id = inv.commercial_partner_id.id
|
||||||
@@ -418,7 +418,7 @@ class AccountStatementLine(orm.Model):
|
|||||||
"""
|
"""
|
||||||
statement_line_obj = self.pool['account.bank.statement.line']
|
statement_line_obj = self.pool['account.bank.statement.line']
|
||||||
model_cols = statement_line_obj._columns
|
model_cols = statement_line_obj._columns
|
||||||
sparse_fields = dict([(k , col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char'])
|
sparse_fields = dict([(k, col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char'])
|
||||||
values = []
|
values = []
|
||||||
for statement in statement_store:
|
for statement in statement_store:
|
||||||
to_json_k = set()
|
to_json_k = set()
|
||||||
@@ -429,10 +429,9 @@ class AccountStatementLine(orm.Model):
|
|||||||
serialized = st_copy.setdefault(col.serialization_field, {})
|
serialized = st_copy.setdefault(col.serialization_field, {})
|
||||||
serialized[k] = st_copy[k]
|
serialized[k] = st_copy[k]
|
||||||
for k in to_json_k:
|
for k in to_json_k:
|
||||||
st_copy[k] = simplejson.dumps(st_copy[k])
|
st_copy[k] = simplejson.dumps(st_copy[k])
|
||||||
values.append(st_copy)
|
values.append(st_copy)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
def _insert_lines(self, cr, uid, statement_store, context=None):
|
def _insert_lines(self, cr, uid, statement_store, context=None):
|
||||||
""" Do raw insert into database because ORM is awfully slow
|
""" Do raw insert into database because ORM is awfully slow
|
||||||
@@ -456,7 +455,7 @@ class AccountStatementLine(orm.Model):
|
|||||||
when cheking security.
|
when cheking security.
|
||||||
TODO / WARM: sparse fields are skipped by the method. IOW, if your
|
TODO / WARM: sparse fields are skipped by the method. IOW, if your
|
||||||
completion rule update an sparse field, the updated value will never
|
completion rule update an sparse field, the updated value will never
|
||||||
be stored in the database. It would be safer to call the update method
|
be stored in the database. It would be safer to call the update method
|
||||||
from the ORM for records updating this kind of fields.
|
from the ORM for records updating this kind of fields.
|
||||||
"""
|
"""
|
||||||
cols = self._get_available_columns([vals])
|
cols = self._get_available_columns([vals])
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
import base64
|
import base64
|
||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
def UnicodeDictReader(utf8_data, **kwargs):
|
def UnicodeDictReader(utf8_data, **kwargs):
|
||||||
@@ -115,6 +114,19 @@ class BankStatementImportParser(object):
|
|||||||
"""
|
"""
|
||||||
return NotImplementedError
|
return NotImplementedError
|
||||||
|
|
||||||
|
def get_st_vals(self):
|
||||||
|
"""
|
||||||
|
This method return a dict of vals that ca be passed to
|
||||||
|
create method of statement.
|
||||||
|
:return: dict of vals that represent additional infos for the statement
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'name': self.statement_name,
|
||||||
|
'balance_start': self.balance_start,
|
||||||
|
'balance_end_real': self.balance_end,
|
||||||
|
'date': self.statement_date
|
||||||
|
}
|
||||||
|
|
||||||
def get_st_line_vals(self, line, *args, **kwargs):
|
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
|
Implement a method in your parser that must return a dict of vals that can be
|
||||||
@@ -155,37 +167,6 @@ class BankStatementImportParser(object):
|
|||||||
self._post(*args, **kwargs)
|
self._post(*args, **kwargs)
|
||||||
return self.result_row_list
|
return self.result_row_list
|
||||||
|
|
||||||
def get_start_balance(self, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
This is called by the importation method to set the balance start
|
|
||||||
amount in the bank statement.
|
|
||||||
return: float of the balance start (self.balance_start)
|
|
||||||
"""
|
|
||||||
return self.balance_start
|
|
||||||
|
|
||||||
def get_end_balance(self, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
This is called by the importation method to set the balance end
|
|
||||||
amount in the bank statement.
|
|
||||||
return: float of the balance end (self.balance_end)
|
|
||||||
"""
|
|
||||||
return self.balance_end
|
|
||||||
|
|
||||||
def get_statement_name(self, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
This is called by the importation method to set the statement
|
|
||||||
name in the bank statement.
|
|
||||||
return: string of the statement name (self.statement_name)
|
|
||||||
"""
|
|
||||||
return self.statement_name or '/'
|
|
||||||
|
|
||||||
def get_statement_date(self, *args, **kwargs):
|
|
||||||
"""
|
|
||||||
This is called by the importation method to set the statement
|
|
||||||
date in the bank statement.
|
|
||||||
return: datetime of the statement date (self.statement_date)
|
|
||||||
"""
|
|
||||||
return self.statement_date or datetime.now()
|
|
||||||
|
|
||||||
def itersubclasses(cls, _seen=None):
|
def itersubclasses(cls, _seen=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class AccountStatementProfil(Model):
|
|||||||
statement_id, context):
|
statement_id, context):
|
||||||
"""
|
"""
|
||||||
Hook to build the values of a line from the parser returned values. At
|
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
|
least it fullfill the statement_id and account_id. Override it to add your
|
||||||
own completion if needed.
|
own completion if needed.
|
||||||
|
|
||||||
:param dict of vals from parser for account.bank.statement.line (called by
|
:param dict of vals from parser for account.bank.statement.line (called by
|
||||||
@@ -126,14 +126,14 @@ class AccountStatementProfil(Model):
|
|||||||
values['type'] = 'general'
|
values['type'] = 'general'
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
def prepare_statement_vals(self, cr, uid, profile_id, result_row_list, parser, context):
|
||||||
def _prepare_statement_vals(self, cr, uid, prof, parser, context=None):
|
"""
|
||||||
return {
|
Hook to build the values of the statement from the parser and
|
||||||
'profile_id': prof.id,
|
the profile.
|
||||||
'name': parser.get_statement_name(),
|
"""
|
||||||
'balance_start': parser.get_start_balance(),
|
vals = {'profile_id': profile_id}
|
||||||
'balance_end_real': parser.get_end_balance(),
|
vals.update(parser.get_st_vals())
|
||||||
}
|
return vals
|
||||||
|
|
||||||
def statement_import(self, cr, 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):
|
||||||
"""
|
"""
|
||||||
@@ -168,8 +168,11 @@ class AccountStatementProfil(Model):
|
|||||||
_("Column %s you try to import is not "
|
_("Column %s you try to import is not "
|
||||||
"present in the bank statement line!") % col)
|
"present in the bank statement line!") % col)
|
||||||
|
|
||||||
st_vals = self._prepare_statement_vals(cr, uid, prof, parser, context=context)
|
statement_vals = self.prepare_statement_vals(cr, uid, prof.id, result_row_list, parser, context)
|
||||||
statement_id = statement_obj.create(cr, uid, st_vals, context=context)
|
statement_id = statement_obj.create(cr, uid,
|
||||||
|
statement_vals,
|
||||||
|
context=context)
|
||||||
|
|
||||||
if prof.receivable_account_id:
|
if prof.receivable_account_id:
|
||||||
account_receivable = account_payable = prof.receivable_account_id.id
|
account_receivable = account_payable = prof.receivable_account_id.id
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ from openerp.tools.translate import _
|
|||||||
import datetime
|
import datetime
|
||||||
from openerp.osv import orm, fields
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
|
||||||
def float_or_zero(val):
|
def float_or_zero(val):
|
||||||
return float(val) if val else 0.0
|
return float(val) if val else 0.0
|
||||||
|
|
||||||
|
|
||||||
class AccountStatementProfil(orm.Model):
|
class AccountStatementProfil(orm.Model):
|
||||||
_inherit = "account.statement.profile"
|
_inherit = "account.statement.profile"
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ class AccountStatementProfil(orm.Model):
|
|||||||
commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False
|
commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False
|
||||||
comm_values = {
|
comm_values = {
|
||||||
'name': 'IN ' + _('Commission line'),
|
'name': 'IN ' + _('Commission line'),
|
||||||
'date': parser.get_statement_date(),
|
'date': parser.get_st_vals().get('date') or datetime.datetime.now(),
|
||||||
'amount': global_commission_amount,
|
'amount': global_commission_amount,
|
||||||
'partner_id': partner_id,
|
'partner_id': partner_id,
|
||||||
'type': 'general',
|
'type': 'general',
|
||||||
@@ -36,6 +38,7 @@ class AccountStatementProfil(orm.Model):
|
|||||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||||
statement_line_obj.create(cr, uid, comm_values, context=context)
|
statement_line_obj.create(cr, uid, comm_values, context=context)
|
||||||
|
|
||||||
|
|
||||||
class AccountStatementLineWithCommission(orm.Model):
|
class AccountStatementLineWithCommission(orm.Model):
|
||||||
_inherit = "account.bank.statement.line"
|
_inherit = "account.bank.statement.line"
|
||||||
_columns = {
|
_columns = {
|
||||||
@@ -45,6 +48,7 @@ class AccountStatementLineWithCommission(orm.Model):
|
|||||||
serialization_field='additionnal_bank_fields'),
|
serialization_field='additionnal_bank_fields'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CreditPartnerStatementImporter(orm.TransientModel):
|
class CreditPartnerStatementImporter(orm.TransientModel):
|
||||||
_inherit = "credit.statement.import"
|
_inherit = "credit.statement.import"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user