mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
First commit to migrate and merge base_import, base_completion and commission
This commit is contained in:
@@ -20,8 +20,7 @@
|
||||
##############################################################################
|
||||
import base64
|
||||
import csv
|
||||
from datetime import datetime
|
||||
from openerp.tools.translate import _
|
||||
from openerp import _, fields
|
||||
|
||||
|
||||
def UnicodeDictReader(utf8_data, **kwargs):
|
||||
@@ -41,7 +40,7 @@ def UnicodeDictReader(utf8_data, **kwargs):
|
||||
for key, value in row.iteritems()])
|
||||
|
||||
|
||||
class BankStatementImportParser(object):
|
||||
class AccountMoveImportParser(object):
|
||||
|
||||
"""
|
||||
Generic abstract class for defining parser for different files and
|
||||
@@ -50,21 +49,19 @@ class BankStatementImportParser(object):
|
||||
from the FileParser instead.
|
||||
"""
|
||||
|
||||
def __init__(self, profile, *args, **kwargs):
|
||||
def __init__(self, journal, *args, **kwargs):
|
||||
# The name of the parser as it will be called
|
||||
self.parser_name = profile.import_type
|
||||
self.parser_name = journal.import_type
|
||||
# The result as a list of row. One row per line of data in the file,
|
||||
# but not the commission one!
|
||||
self.result_row_list = None
|
||||
# The file buffer on which to work on
|
||||
self.filebuffer = None
|
||||
# The profile record to access its parameters in any parser method
|
||||
self.profile = profile
|
||||
self.balance_start = None
|
||||
self.balance_end = None
|
||||
self.statement_name = None
|
||||
self.statement_date = None
|
||||
self.support_multi_statements = False
|
||||
self.journal = journal
|
||||
self.move_date = None
|
||||
self.move_name = None
|
||||
self.move_ref= None
|
||||
|
||||
@classmethod
|
||||
def parser_for(cls, parser_name):
|
||||
@@ -119,19 +116,18 @@ class BankStatementImportParser(object):
|
||||
"""
|
||||
return NotImplementedError
|
||||
|
||||
def get_st_vals(self):
|
||||
def get_move_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 or '/',
|
||||
'balance_start': self.balance_start,
|
||||
'balance_end_real': self.balance_end,
|
||||
'date': self.statement_date or datetime.now()
|
||||
'name': self.move_name or '/',
|
||||
'date': self.move_date or fields.Datetime.now(),
|
||||
'ref': self.move_ref or '/'
|
||||
}
|
||||
|
||||
def get_st_line_vals(self, line, *args, **kwargs):
|
||||
def get_move_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 of every parser to give this dict
|
||||
@@ -165,16 +161,10 @@ class BankStatementImportParser(object):
|
||||
raise Exception(_('No buffer file given.'))
|
||||
self._format(*args, **kwargs)
|
||||
self._pre(*args, **kwargs)
|
||||
if self.support_multi_statements:
|
||||
while self._parse(*args, **kwargs):
|
||||
self._validate(*args, **kwargs)
|
||||
self._post(*args, **kwargs)
|
||||
yield self.result_row_list
|
||||
else:
|
||||
self._parse(*args, **kwargs)
|
||||
self._validate(*args, **kwargs)
|
||||
self._post(*args, **kwargs)
|
||||
yield self.result_row_list
|
||||
self._parse(*args, **kwargs)
|
||||
self._validate(*args, **kwargs)
|
||||
self._post(*args, **kwargs)
|
||||
yield self.result_row_list
|
||||
|
||||
|
||||
def itersubclasses(cls, _seen=None):
|
||||
@@ -218,13 +208,13 @@ def itersubclasses(cls, _seen=None):
|
||||
yield sub
|
||||
|
||||
|
||||
def new_bank_statement_parser(profile, *args, **kwargs):
|
||||
def new_move_parser(journal, *args, **kwargs):
|
||||
"""Return an instance of the good parser class based on the given profile.
|
||||
|
||||
:param profile: browse_record of import profile.
|
||||
:return: class instance for given profile import type.
|
||||
"""
|
||||
for cls in itersubclasses(BankStatementImportParser):
|
||||
if cls.parser_for(profile.import_type):
|
||||
return cls(profile, *args, **kwargs)
|
||||
for cls in itersubclasses(AccountMoveImportParser):
|
||||
if cls.parser_for(journal.import_type):
|
||||
return cls(journal, *args, **kwargs)
|
||||
raise ValueError
|
||||
|
||||
Reference in New Issue
Block a user