~pedro.baeza/banking-addons/bank-statement-reconcile-7.0-base_completion_imp

« back to all changes in this revision

Viewing changes to account_statement_base_import/statement.py

  • Committer: Yannick Vaucher
  • Author(s): laurent.mignon at acsone
  • Date: 2014-05-19 06:54:57 UTC
  • mfrom: (146.1.6 addons-banking)
  • Revision ID: yannick.vaucher@camptocamp.com-20140519065457-1k17upu7mmnkuofz
[IMP] Give the possibility to parse and import multiple statments

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
        vals.update(parser.get_st_vals())
137
137
        return vals
138
138
 
139
 
    def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None):
 
139
    def multi_statement_import(self, cr, uid, ids, profile_id, file_stream,
 
140
                               ftype="csv", context=None):
 
141
        """
 
142
        Create multiple bank statements from values given by the parser for the
 
143
         givenprofile.
 
144
 
 
145
        :param int/long profile_id: ID of the profile used to import the file
 
146
        :param filebuffer file_stream: binary of the providen file
 
147
        :param char: ftype represent the file exstension (csv by default)
 
148
        :return: list: list of ids of the created account.bank.statemênt
 
149
        """
 
150
        prof_obj = self.pool['account.statement.profile']
 
151
        if not profile_id:
 
152
            raise osv.except_osv(_("No Profile!"),
 
153
             _("You must provide a valid profile to import a bank statement!"))
 
154
        prof = prof_obj.browse(cr, uid, profile_id, context=context)
 
155
 
 
156
        parser = new_bank_statement_parser(prof.import_type, ftype=ftype)
 
157
        res = []
 
158
        for result_row_list in parser.parse(file_stream):
 
159
            statement_id = self._statement_import(cr, uid, ids, prof, parser,
 
160
                                    file_stream, ftype=ftype, context=context)
 
161
            res.append(statement_id)
 
162
        return res
 
163
 
 
164
    def _statement_import(self, cr, uid, ids, prof, parser, file_stream, ftype="csv", context=None):
140
165
        """
141
166
        Create a bank statement with the given profile and parser. It will fullfill the bank statement
142
167
        with the values of the file providen, but will not complete data (like finding the partner, or
143
168
        the right account). This will be done in a second step with the completion rules.
144
169
 
145
 
        :param int/long profile_id: ID of the profile used to import the file
 
170
        :param prof : The profile used to import the file
 
171
        :param parser: the parser
146
172
        :param filebuffer file_stream: binary of the providen file
147
173
        :param char: ftype represent the file exstension (csv by default)
148
174
        :return: ID of the created account.bank.statemênt
150
176
        statement_obj = self.pool.get('account.bank.statement')
151
177
        statement_line_obj = self.pool.get('account.bank.statement.line')
152
178
        attachment_obj = self.pool.get('ir.attachment')
153
 
        prof_obj = self.pool.get("account.statement.profile")
154
 
        if not profile_id:
155
 
            raise osv.except_osv(_("No Profile!"),
156
 
                                 _("You must provide a valid profile to import a bank statement!"))
157
 
        prof = prof_obj.browse(cr, uid, profile_id, context=context)
158
179
 
159
 
        parser = new_bank_statement_parser(prof.import_type, ftype=ftype)
160
 
        result_row_list = parser.parse(file_stream)
 
180
        result_row_list = parser.result_row_list
161
181
        # Check all key are present in account.bank.statement.line!!
162
182
        if not result_row_list:
163
183
            raise osv.except_osv(_("Nothing to import"),