Add fields "account" and "partner" as non-mandatory

This commit is contained in:
Matthieu Dietrich
2016-04-29 13:56:09 +02:00
parent f7f26f7d25
commit b765565bcd
2 changed files with 23 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ class FileParser(AccountMoveImportParser):
format.
"""
def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None,
def __init__(self, journal, ftype='csv', extra_fields=None, header=None,
dialect=None, move_ref=None, **kwargs):
"""
:param char: parse_name: The name of the parser
@@ -50,7 +50,7 @@ class FileParser(AccountMoveImportParser):
:param list: header : specify header fields if the csv file has no
header
"""
super(FileParser, self).__init__(parse_name, **kwargs)
super(FileParser, self).__init__(journal, **kwargs)
if ftype in ('csv', 'xls', 'xlsx'):
self.ftype = ftype[0:3]
else:

View File

@@ -33,14 +33,16 @@ class GenericFileParser(FileParser):
file.
"""
def __init__(self, parse_name, ftype='csv', **kwargs):
def __init__(self, journal, ftype='csv', **kwargs):
conversion_dict = {
'label': ustr,
'date': datetime.datetime,
'amount': float_or_zero,
}
# set self.env for later ORM searches
self.env = journal.env
super(GenericFileParser, self).__init__(
parse_name, ftype=ftype,
journal, ftype=ftype,
extra_fields=conversion_dict,
**kwargs)
@@ -68,10 +70,27 @@ class GenericFileParser(FileParser):
'debit':value
}
"""
account_obj = self.env['account.account']
partner_obj = self.env['res.partner']
account_id = False
partner_id = False
if line.get('account'):
accounts = account_obj.search([('code', '=', line['account'])])
if len(accounts) == 1:
account_id = accounts[0].id
if line.get('partner'):
partners = partner_obj.search([('name', '=', line['partner'])])
if len(partners) == 1:
partner_id = partners[0].id
amount = line.get('amount', 0.0)
return {
'name': line.get('label', '/'),
'date_maturity': line.get('date', datetime.datetime.now().date()),
'credit': amount > 0.0 and amount or 0.0,
'debit': amount < 0.0 and amount or 0.0,
'account_id': account_id,
'partner_id': partner_id,
}