From 0698aed4267b0fd60fc0f9c72cd8ce175ab18662 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Wed, 27 Apr 2016 10:49:20 +0200 Subject: [PATCH] Follow-up on migration --- .../security/ir.model.access.csv | 3 -- account_statement_base_import/__openerp__.py | 1 + .../data/completion_rule_data.xml | 4 +- .../data/statement.csv | 8 ++-- .../models/account_journal.py | 16 ++++++-- .../models/account_move.py | 11 +++--- .../parser/file_parser.py | 3 +- .../parser/generic_file_parser.py | 8 ++-- .../parser/parser.py | 2 +- .../security/ir.model.access.csv | 3 ++ .../views/account_move_view.xml | 39 +++++++++++++++++++ .../views/journal_view.xml | 9 +++-- .../wizard/import_statement.py | 26 +++++++------ .../wizard/import_statement_view.xml | 14 ++++--- 14 files changed, 102 insertions(+), 45 deletions(-) delete mode 100644 account_statement_base_completion/security/ir.model.access.csv create mode 100644 account_statement_base_import/security/ir.model.access.csv diff --git a/account_statement_base_completion/security/ir.model.access.csv b/account_statement_base_completion/security/ir.model.access.csv deleted file mode 100644 index 4fb32325..00000000 --- a/account_statement_base_completion/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_account_bank_st_cmpl_user,account.statement.completion.rule,model_account_statement_completion_rule,account.group_account_user,1,0,0,0 -access_account_bank_st_cmpl_manager,account.statement.completion.rule,model_account_statement_completion_rule,account.group_account_manager,1,1,1,1 diff --git a/account_statement_base_import/__openerp__.py b/account_statement_base_import/__openerp__.py index 5a576242..3612ef25 100644 --- a/account_statement_base_import/__openerp__.py +++ b/account_statement_base_import/__openerp__.py @@ -61,6 +61,7 @@ """, 'website': 'http://www.camptocamp.com', 'data': [ + "security/ir.model.access.csv", "data/completion_rule_data.xml", "wizard/import_statement_view.xml", "views/account_move_view.xml", diff --git a/account_statement_base_import/data/completion_rule_data.xml b/account_statement_base_import/data/completion_rule_data.xml index d9d738b4..b06ac51a 100644 --- a/account_statement_base_import/data/completion_rule_data.xml +++ b/account_statement_base_import/data/completion_rule_data.xml @@ -14,9 +14,9 @@ - Match from line reference (based on Invoice reference) + Match from line label (based on Invoice reference) 40 - get_from_ref_and_invoice + get_from_name_and_invoice diff --git a/account_statement_base_import/data/statement.csv b/account_statement_base_import/data/statement.csv index fa059787..21dead31 100644 --- a/account_statement_base_import/data/statement.csv +++ b/account_statement_base_import/data/statement.csv @@ -1,4 +1,4 @@ -"ref";"date";"amount";"commission_amount";"label" -50969286;2011-03-07 13:45:14;118.4;-11.84;"label a" -51065326;2011-03-02 13:45:14;189;-15.12;"label b" -51179306;2011-03-02 17:45:14;189;-15.12;"label c" +"date";"amount";"commission_amount";"label" +2011-03-07 13:45:14;118.4;-11.84;"label a" +2011-03-02 13:45:14;189;-15.12;"label b" +2011-03-02 17:45:14;189;-15.12;"label c" diff --git a/account_statement_base_import/models/account_journal.py b/account_statement_base_import/models/account_journal.py index 5ee7941c..a820df33 100644 --- a/account_statement_base_import/models/account_journal.py +++ b/account_statement_base_import/models/account_journal.py @@ -20,6 +20,7 @@ ############################################################################## import sys import traceback +import os from openerp import _, api, fields, models from ..parser.parser import new_move_parser from openerp.exceptions import UserError, ValidationError @@ -38,6 +39,9 @@ class AccountJournal(models.Model): """ Call method which can be inherited """ return self._get_import_type_selection() + used_for_import = fields.Boolean( + string="Journal used for import") + commission_account_id = fields.Many2one( comodel_name='account.account', string='Commission account') @@ -173,7 +177,7 @@ class AccountJournal(models.Model): def prepare_move_line_vals(self, parser_vals, move): """Hook to build the values of a line from the parser returned values. - At least it fullfill the statement_id. Overide it to add your own + At least it fullfill the basic values. Overide it to add your own completion if needed. :param dict of vals from parser for account.bank.statement.line @@ -186,6 +190,8 @@ class AccountJournal(models.Model): move_line_obj = self.env['account.move.line'] values = parser_vals values['company_id'] = self.company_id.id + values['currency_id'] = self.currency_id.id + values['company_currency_id'] = self.company_id.currency_id.id values['journal_id'] = self.id values['move_id'] = move.id if values['credit'] > 0.0: @@ -199,7 +205,8 @@ class AccountJournal(models.Model): """Hook to build the values of the statement from the parser and the profile. """ - vals = {'journal_id': self.id} + vals = {'journal_id': self.id, + 'currency_id': self.currency_id.id} vals.update(parser.get_move_vals()) return vals @@ -212,7 +219,10 @@ class AccountJournal(models.Model): :param char: ftype represent the file exstension (csv by default) :return: list: list of ids of the created account.bank.statemĂȘnt """ - parser = new_move_parser(self, ftype=ftype) + filename = self._context.get('file_name', None) + if filename: + (filename, __) = os.path.splitext(filename) + parser = new_move_parser(self, ftype=ftype, move_ref=filename) res = [] for result_row_list in parser.parse(file_stream): move = self._move_import(parser, file_stream, ftype=ftype) diff --git a/account_statement_base_import/models/account_move.py b/account_statement_base_import/models/account_move.py index edfa2f53..cc68b393 100644 --- a/account_statement_base_import/models/account_move.py +++ b/account_statement_base_import/models/account_move.py @@ -64,8 +64,8 @@ class AccountMoveCompletionRule(models.Model): Override this to add you own.""" return [ - ('get_from_ref_and_invoice', - 'From line reference (based on invoice reference)'), + ('get_from_name_and_invoice', + 'From line name (based on invoice reference)'), ('get_from_name_and_partner_field', 'From line name (based on partner field)'), ('get_from_name_and_partner_name', @@ -91,7 +91,7 @@ class AccountMoveCompletionRule(models.Model): string='Method') # Should be private but data are initialised with no update XML - def get_from_ref_and_invoice(self, line): + def get_from_name_and_invoice(self, line): """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 @@ -107,8 +107,7 @@ class AccountMoveCompletionRule(models.Model): """ res = {} inv_obj = self.env['account.invoice'] - - invoices = inv_obj.search([('reference', '=', line.ref.strip())]) + invoices = inv_obj.search([('name', '=', line.name.strip())]) if invoices: if len(invoices) == 1: invoice = invoices[0] @@ -118,7 +117,7 @@ class AccountMoveCompletionRule(models.Model): raise ErrorTooManyPartner( _('Line named "%s" (Ref:%s) was matched by more than one ' 'partner while looking on invoices') % - (line.name, line.ref)) + (line.name)) return res # Should be private but data are initialised with no update XML diff --git a/account_statement_base_import/parser/file_parser.py b/account_statement_base_import/parser/file_parser.py index eade8486..eb5bd2f4 100644 --- a/account_statement_base_import/parser/file_parser.py +++ b/account_statement_base_import/parser/file_parser.py @@ -40,7 +40,7 @@ class FileParser(AccountMoveImportParser): """ def __init__(self, parse_name, ftype='csv', extra_fields=None, header=None, - dialect=None, **kwargs): + dialect=None, move_ref=None, **kwargs): """ :param char: parse_name: The name of the parser :param char: ftype: extension of the file (could be csv, xls or @@ -63,6 +63,7 @@ class FileParser(AccountMoveImportParser): # 0 means Windows mode (1900 based dates). # Set in _parse_xls, from the contents of the file self.dialect = dialect + self.move_ref = move_ref def _custom_format(self, *args, **kwargs): """No other work on data are needed in this parser.""" diff --git a/account_statement_base_import/parser/generic_file_parser.py b/account_statement_base_import/parser/generic_file_parser.py index 38879aac..863ab880 100644 --- a/account_statement_base_import/parser/generic_file_parser.py +++ b/account_statement_base_import/parser/generic_file_parser.py @@ -35,7 +35,6 @@ class GenericFileParser(FileParser): def __init__(self, parse_name, ftype='csv', **kwargs): conversion_dict = { - 'ref': ustr, 'label': ustr, 'date': datetime.datetime, 'amount': float_or_zero, @@ -64,10 +63,9 @@ class GenericFileParser(FileParser): line, it MUST contain at least: { 'name':value, - 'date':value, - 'amount':value, - 'ref':value, - 'label':value, + 'date_maturity':value, + 'credit':value, + 'debit':value } """ amount = line.get('amount', 0.0) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index a38a8620..696290da 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -61,7 +61,7 @@ class AccountMoveImportParser(object): self.journal = journal self.move_date = None self.move_name = None - self.move_ref= None + self.move_ref = None @classmethod def parser_for(cls, parser_name): diff --git a/account_statement_base_import/security/ir.model.access.csv b/account_statement_base_import/security/ir.model.access.csv new file mode 100644 index 00000000..17974849 --- /dev/null +++ b/account_statement_base_import/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_bank_st_cmpl_user,account.move.completion.rule,model_account_move_completion_rule,account.group_account_user,1,0,0,0 +access_account_bank_st_cmpl_manager,account.move.completion.rule,model_account_move_completion_rule,account.group_account_manager,1,1,1,1 diff --git a/account_statement_base_import/views/account_move_view.xml b/account_statement_base_import/views/account_move_view.xml index c9d43adb..57807834 100644 --- a/account_statement_base_import/views/account_move_view.xml +++ b/account_statement_base_import/views/account_move_view.xml @@ -17,4 +17,43 @@ + + + account.move.completion.rule.view + account.move.completion.rule + +
+ + + + + + + + + +
+ + + account.move.completion.rule.view + account.move.completion.rule + + + + + + + + + + + + Move Completion Rule + account.move.completion.rule + form + tree,form + + + diff --git a/account_statement_base_import/views/journal_view.xml b/account_statement_base_import/views/journal_view.xml index fecfca31..6e7bbf15 100644 --- a/account_statement_base_import/views/journal_view.xml +++ b/account_statement_base_import/views/journal_view.xml @@ -5,11 +5,14 @@ account.journal + + + - + - + @@ -18,7 +21,7 @@ -