From 65c6e9af8a3d4f201bb79193d82337d6ae995ac1 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 15 Jan 2020 11:21:49 +0100 Subject: [PATCH] - pass pattern to _list --- attachment_synchronize/models/task.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/attachment_synchronize/models/task.py b/attachment_synchronize/models/task.py index 73b3de061..42bcb6eac 100644 --- a/attachment_synchronize/models/task.py +++ b/attachment_synchronize/models/task.py @@ -3,7 +3,6 @@ import datetime import logging import os -from fnmatch import fnmatch import odoo from odoo import api, fields, models, tools @@ -50,10 +49,10 @@ class StorageTask(models.Model): method_type = fields.Selection( [('import', 'Import'), ('export', 'Export')], required=True) - filename = fields.Char(help='File name which is imported.' - 'The system will check if the remote file at ' - 'least contains the pattern in its name. ' - 'Leave it empty to import all files') + pattern = fields.Char(help='File name which is imported.' + 'The system will check if the remote file at ' + 'least contains the pattern in its name. ' + 'Leave it empty to import all files') filepath = fields.Char(help='Path to imported/exported file') backend_id = fields.Many2one( 'storage.backend', string='Backend', required=True) @@ -125,9 +124,8 @@ class StorageTask(models.Model): self.ensure_one() attach_obj = self.env['ir.attachment.metadata'] backend = self.backend_id - all_filenames = backend._list(relative_path=self.filepath) - if self.filename: - filenames = [x for x in all_filenames if fnmatch(x, self.filename)] + filenames = backend._list( + relative_path=self.filepath, pattern=self.pattern) for file_name in filenames: with api.Environment.manage(): with odoo.registry(