diff --git a/attachment_base_synchronize/README.rst b/attachment_base_synchronize/README.rst index a609c314a..87761b30e 100644 --- a/attachment_base_synchronize/README.rst +++ b/attachment_base_synchronize/README.rst @@ -6,16 +6,14 @@ Attachment Metadata ==================== -This module extend ir.attachment model with some new fields for a better control -for import and export of files. +This module extends ir.attachment model with some new fields for a better control for import and export of files. The main feature is an integrity file check with a hash. A file hash is short representation (signature) computed from file data. -Hashes computed before send file and after received file can be compared to be -sure of the content integrity. +Hashes computed before send file and after received file can be compared to be sure of the content integrity. -An example of the use of this module, can be found in the external_file_location. +An example of the use of this module, can be found in the module `external_file_location`. Usage @@ -25,6 +23,10 @@ Go the menu Settings > Technical > Database Structure > Meta Data Attachments You can create / see standard attachments with additional fields +Configure the batch limit for attachments that can be sync by the cron task at a go: + +Settings > Technical > System parameters > attachment_sync_cron_batch_limit + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas @@ -61,6 +63,7 @@ Contributors * Valentin CHEMIERE * Florian da Costa * Angel Moya +* Dan Kiplangat Maintainer ---------- diff --git a/attachment_base_synchronize/__manifest__.py b/attachment_base_synchronize/__manifest__.py index 658879657..58860305d 100644 --- a/attachment_base_synchronize/__manifest__.py +++ b/attachment_base_synchronize/__manifest__.py @@ -1,11 +1,12 @@ -# coding: utf-8 -# @ 2015 Florian DA COSTA @ Akretion +# Copyright 2015 Florian DA COSTA @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Attachment Base Synchronize', - 'version': '10.0.1.0.0', + 'version': '11.0.1.0.0', 'author': 'Akretion,Odoo Community Association (OCA)', + 'summary': 'This module enhances ir.attachment for better ' + 'control of import and export of files', 'website': 'https://www.akretion.com', 'license': 'AGPL-3', 'category': 'Generic Modules', @@ -17,6 +18,7 @@ 'views/attachment_view.xml', 'security/ir.model.access.csv', 'data/cron.xml', + 'data/ir_config_parameter.xml', ], 'demo': [ 'demo/attachment_metadata_demo.xml' diff --git a/attachment_base_synchronize/data/cron.xml b/attachment_base_synchronize/data/cron.xml index 47c82b150..677fcc446 100644 --- a/attachment_base_synchronize/data/cron.xml +++ b/attachment_base_synchronize/data/cron.xml @@ -1,16 +1,16 @@ - - Run Attachments Metadata - 30 - minutes - -1 - False - - ir.attachment.metadata - run_attachment_metadata_scheduler - ([]) - + + Run Attachments Metadata + 30 + minutes + -1 + False + + + code + model.run_attachment_metadata_scheduler() + diff --git a/attachment_base_synchronize/data/ir_config_parameter.xml b/attachment_base_synchronize/data/ir_config_parameter.xml new file mode 100644 index 000000000..fa726d03d --- /dev/null +++ b/attachment_base_synchronize/data/ir_config_parameter.xml @@ -0,0 +1,7 @@ + + + + attachment_sync_cron_batch_limit + 200 + + diff --git a/attachment_base_synchronize/models/attachment.py b/attachment_base_synchronize/models/attachment.py index 81d7d5b13..bafb891a9 100644 --- a/attachment_base_synchronize/models/attachment.py +++ b/attachment_base_synchronize/models/attachment.py @@ -1,13 +1,10 @@ -# coding: utf-8 -# @ 2015 Florian DA COSTA @ Akretion +# Copyright 2015 Florian DA COSTA @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from base64 import b64decode import hashlib import logging -import odoo -from odoo import _, api, fields, models -from odoo.exceptions import UserError +from odoo import _, api, exceptions, fields, models, registry _logger = logging.getLogger(__name__) @@ -31,7 +28,6 @@ class IrAttachmentMetadata(models.Model): help="Link to ir.attachment model ") file_type = fields.Selection( selection=[], - string="File type", help="The file type determines an import method to be used " "to parse and transform data before their import in ERP or an export") sync_date = fields.Datetime() @@ -50,7 +46,7 @@ class IrAttachmentMetadata(models.Model): b64decode(attachment.datas)).hexdigest() if attachment.external_hash and\ attachment.internal_hash != attachment.external_hash: - raise UserError( + raise exceptions.UserError( _("File corrupted: Something was wrong with " "the retrieved file, please relaunch the task.")) @@ -58,7 +54,14 @@ class IrAttachmentMetadata(models.Model): def run_attachment_metadata_scheduler(self, domain=None): if domain is None: domain = [('state', '=', 'pending')] - attachments = self.search(domain) + batch_limit = self.env.ref( + 'attachment_base_synchronize.attachment_sync_cron_batch_limit') \ + .value + if batch_limit and batch_limit.isdigit(): + limit = int(batch_limit) + else: + limit = 200 + attachments = self.search(domain, limit=limit) if attachments: return attachments.run() return True @@ -70,20 +73,20 @@ class IrAttachmentMetadata(models.Model): """ for attachment in self: with api.Environment.manage(): - with odoo.registry(self.env.cr.dbname).cursor() as new_cr: + with registry(self.env.cr.dbname).cursor() as new_cr: new_env = api.Environment( new_cr, self.env.uid, self.env.context) attach = attachment.with_env(new_env) try: attach._run() - except Exception, e: + # pylint: disable=broad-except + except Exception as e: attach.env.cr.rollback() - _logger.exception(e) - attach.write( - { - 'state': 'failed', - 'state_message': e, - }) + _logger.exception(str(e)) + attach.write({ + 'state': 'failed', + 'state_message': str(e), + }) attach.env.cr.commit() else: vals = { @@ -97,7 +100,7 @@ class IrAttachmentMetadata(models.Model): @api.multi def _run(self): self.ensure_one() - _logger.info('Start to process attachment metadata id %s' % self.id) + _logger.info('Start to process attachment metadata id %d', self.id) @api.multi def set_done(self): diff --git a/attachment_base_synchronize/security/ir.model.access.csv b/attachment_base_synchronize/security/ir.model.access.csv index a3628dbba..a886558da 100644 --- a/attachment_base_synchronize/security/ir.model.access.csv +++ b/attachment_base_synchronize/security/ir.model.access.csv @@ -1,3 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_attachment_metadata_user,ir.attachment.metadata.user,model_ir_attachment_metadata,,1,0,0,0 -access_attachment_metadata_user,ir.attachment.metadata.user,model_ir_attachment_metadata,base.group_no_one,1,1,1,1 +access_attachment_metadata_manager,ir.attachment.metadata.manager,model_ir_attachment_metadata,base.group_no_one,1,1,1,1 diff --git a/attachment_base_synchronize/tests/__init__.py b/attachment_base_synchronize/tests/__init__.py index ef5480f44..dc9b248dd 100644 --- a/attachment_base_synchronize/tests/__init__.py +++ b/attachment_base_synchronize/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Angel Moya (http://angelmoya.es) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/attachment_base_synchronize/tests/test_attachment_base_synchronize.py b/attachment_base_synchronize/tests/test_attachment_base_synchronize.py index a4f90abdf..b7cd511f9 100644 --- a/attachment_base_synchronize/tests/test_attachment_base_synchronize.py +++ b/attachment_base_synchronize/tests/test_attachment_base_synchronize.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2016 Angel Moya (http://angelmoya.es) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -30,7 +29,7 @@ class TestAttachmentBaseSynchronize(TransactionCase): 'pending' ) self.ir_attachment_metadata.run_attachment_metadata_scheduler() - self.env.invalidate_all() + self.env.cache.invalidate() with odoo.registry(self.env.cr.dbname).cursor() as new_cr: new_env = api.Environment( new_cr, self.env.uid, self.env.context) diff --git a/attachment_base_synchronize/views/attachment_view.xml b/attachment_base_synchronize/views/attachment_view.xml index 28dfaf702..6da7b42a0 100644 --- a/attachment_base_synchronize/views/attachment_view.xml +++ b/attachment_base_synchronize/views/attachment_view.xml @@ -28,10 +28,10 @@ - + ir.attachment.metadata - +