Browse Source

Merge PR #1757 into 12.0

Signed-off-by rvalyi
12.0-mig-module_prototyper_last
OCA-git-bot 4 years ago
parent
commit
4299d10ad5
  1. 10
      .travis.yml
  2. 123
      attachment_synchronize/README.rst
  3. 1
      attachment_synchronize/__init__.py
  4. 28
      attachment_synchronize/__manifest__.py
  5. 16
      attachment_synchronize/data/cron.xml
  6. 25
      attachment_synchronize/demo/attachment_synchronize_task_demo.xml
  7. 1
      attachment_synchronize/models/__init__.py
  8. 39
      attachment_synchronize/models/attachment_queue.py
  9. 209
      attachment_synchronize/models/attachment_synchronize_task.py
  10. 67
      attachment_synchronize/models/storage_backend.py
  11. 10
      attachment_synchronize/readme/CONTRIBUTORS.rst
  12. 5
      attachment_synchronize/readme/DESCRIPTION.rst
  13. 19
      attachment_synchronize/readme/USAGE.rst
  14. 2
      attachment_synchronize/security/ir.model.access.csv
  15. BIN
      attachment_synchronize/static/description/export_task.png
  16. BIN
      attachment_synchronize/static/description/icon.png
  17. BIN
      attachment_synchronize/static/description/import_task.png
  18. 448
      attachment_synchronize/static/description/index.html
  19. 2
      attachment_synchronize/tests/__init__.py
  20. 43
      attachment_synchronize/tests/common.py
  21. 42
      attachment_synchronize/tests/test_export.py
  22. 83
      attachment_synchronize/tests/test_import.py
  23. 35
      attachment_synchronize/views/attachment_queue_views.xml
  24. 177
      attachment_synchronize/views/attachment_synchronize_task_views.xml
  25. 34
      attachment_synchronize/views/storage_backend_views.xml

10
.travis.yml

@ -13,21 +13,25 @@ addons:
env: env:
global: global:
- VERSION="12.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0"
- VERSION="12.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0" MQT_DEP="PIP"
- COUNTRY="US" - COUNTRY="US"
matrix: matrix:
- LINT_CHECK="1" - LINT_CHECK="1"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="database_cleanup"
- TESTS="1" ODOO_REPO="OCA/OCB" EXCLUDE="database_cleanup,module_analysis"
- TESTS="1" ODOO_REPO="OCA/OCB" INCLUDE="database_cleanup" - TESTS="1" ODOO_REPO="OCA/OCB" INCLUDE="database_cleanup"
- TESTS="1" ODOO_REPO="odoo/odoo" EXCLUDE="database_cleanup" MAKEPOT="1"
- TESTS="1" ODOO_REPO="OCA/OCB" INCLUDE="module_analysis"
- TESTS="1" ODOO_REPO="odoo/odoo" EXCLUDE="database_cleanup,module_analysis" MAKEPOT="1"
- TESTS="1" ODOO_REPO="odoo/odoo" INCLUDE="database_cleanup" MAKEPOT="1" - TESTS="1" ODOO_REPO="odoo/odoo" INCLUDE="database_cleanup" MAKEPOT="1"
- TESTS="1" ODOO_REPO="odoo/odoo" INCLUDE="module_analysis" MAKEPOT="1"
install: install:
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly - travis_install_nightly
# Requirements to test server_environment modules
- printf '[options]\n\nrunning_env = dev\n' > ${HOME}/.openerp_serverrc
script: script:
- travis_run_tests - travis_run_tests

123
attachment_synchronize/README.rst

@ -0,0 +1,123 @@
======================
Attachment Synchronize
======================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/12.0/attachment_synchronize
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-attachment_synchronize
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/149/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module allows to **import/export files** from/to backend servers.
A backend server is defined by the basic `storage_backend <https://github.com/OCA/storage/tree/12.0/storage_backend>`_ OCA module, while it can be configured (amazon S3, sftp,...) with additional modules from the `storage <https://github.com/oca/storage>`_ repository.
The imported files (and the files to be exported) are stored in Odoo as ``attachment.queue`` objects, defined by the `attachment_queue <https://github.com/OCA/server-tools/tree/12.0/attachment_queue>`_ module while the importation itself (resp. exportation) is realized by **"Attachments Import Tasks"** (resp. "Attachments Export Tasks") defined by this current module.
**Table of contents**
.. contents::
:local:
Usage
=====
As importation and exportation are different processes, they are triggered in different ways :
**To import files**, you need to create an *"Attachment Import Task"* (menu *Settings > Technical > Attachments Import Tasks*) which defines :
- where to find the files to import from the backend server (path to the files, selection pattern)
- what to do with the source files in the backend server (avoid duplicates, delete/rename after import...)
- how the files will be processed once imported (through the **File Type** field).
.. image:: https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/import_task.png
.. epigraph::
🔎 The **File Type** options are defined by other modules built to process the Attachments Queues with the same "File Type".
**To export files**, you need first to register them as *"Attachments Queues"* objects linked to an *"Attachment Export Task"* (which set automatically their **File Type** to *"Export File (External Location)"*).
Then, you can export one file at a time from the *Attachment Queue*'s form view, or export all the *Attachments Queues* in a pending state related to the same *Export Task* from the given *Export Task* form view (menu *Settings > Technical > Attachments Export Tasks*) :
.. image:: https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/export_task.png
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20attachment_synchronize%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Akretion
Contributors
~~~~~~~~~~~~
`Akretion <https://www.akretion.com/>`_ :
- Valentin CHEMIERE
- Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
- Florian DA COSTA <florian.dacosta@akretion.com>
- Clément MOMBEREAU <clement.mombereau@akretion.com.br>
GS Lab:
- Giovanni SERRA <giovanni@gslab.it>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
:target: https://github.com/florian-dacosta
:alt: florian-dacosta
.. |maintainer-GSLabIt| image:: https://github.com/GSLabIt.png?size=40px
:target: https://github.com/GSLabIt
:alt: GSLabIt
.. |maintainer-bealdav| image:: https://github.com/bealdav.png?size=40px
:target: https://github.com/bealdav
:alt: bealdav
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-florian-dacosta| |maintainer-GSLabIt| |maintainer-bealdav|
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/12.0/attachment_synchronize>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

1
attachment_synchronize/__init__.py

@ -0,0 +1 @@
from . import models

28
attachment_synchronize/__manifest__.py

@ -0,0 +1,28 @@
# @ 2016 florian DA COSTA @ Akretion
# © 2016 @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# @ 2020 Giovanni Serra @ GSlab.it
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Attachment Synchronize",
"version": "12.0.1.0.0",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/oca/server-tools",
"maintainers": ["florian-dacosta", "sebastienbeau", "GSLabIt", "bealdav"],
"license": "AGPL-3",
"category": "Generic Modules",
"depends": [
"attachment_queue",
"storage_backend", # https://github.com/OCA/storage
],
"data": [
"views/attachment_queue_views.xml",
"views/attachment_synchronize_task_views.xml",
"views/storage_backend_views.xml",
"data/cron.xml",
"security/ir.model.access.csv",
],
"demo": ["demo/attachment_synchronize_task_demo.xml"],
"installable": True,
"development_status": "Beta",
}

16
attachment_synchronize/data/cron.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">
<record model="ir.cron" id="cronjob_run_attachment_synchronize_task_import">
<field name='name'>Run attachment tasks import</field>
<field name='interval_number'>30</field>
<field name='interval_type'>minutes</field>
<field name="numbercall">-1</field>
<field name="active">False</field>
<field name="doall" eval="False" />
<field name="model_id" ref="model_attachment_synchronize_task"/>
<field name="state">code</field>
<field name="code">model.run_task_import_scheduler()</field>
</record>
</odoo>

25
attachment_synchronize/demo/attachment_synchronize_task_demo.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="import_from_filestore" model="attachment.synchronize.task">
<field name="name">TEST Import</field>
<field name="backend_id" ref="storage_backend.default_storage_backend"/>
<field name="method_type">import</field>
<field name="after_import">delete</field>
<field name="filepath">test_import</field>
</record>
<record id="export_to_filestore" model="attachment.synchronize.task">
<field name="name">TEST Export</field>
<field name="backend_id" ref="storage_backend.default_storage_backend"/>
<field name="method_type">export</field>
<field name="filepath">test_export</field>
</record>
<record id="attachment_queue_imported_demo" model="attachment.queue">
<field name="datas">bWlncmF0aW9uIHRlc3Q=</field>
<field name="datas_fname">attachment_queue_imported_demo.doc</field>
<field name="name">attachment_queue_imported_demo.doc</field>
<field name="task_id" ref="import_from_filestore" />
</record>
</odoo>

1
attachment_synchronize/models/__init__.py

@ -0,0 +1 @@
from . import attachment_queue, attachment_synchronize_task, storage_backend

39
attachment_synchronize/models/attachment_queue.py

@ -0,0 +1,39 @@
# @ 2016 Florian DA COSTA @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os
from odoo import api, models, fields
class AttachmentQueue(models.Model):
_inherit = "attachment.queue"
task_id = fields.Many2one("attachment.synchronize.task", string="Task")
method_type = fields.Selection(related="task_id.method_type")
storage_backend_id = fields.Many2one(
"storage.backend",
string="Storage Backend",
related="task_id.backend_id",
store=True,
)
file_type = fields.Selection(
selection_add=[("export", "Export File (External location)")]
)
def _run(self):
super()._run()
if self.file_type == "export":
path = os.path.join(self.task_id.filepath, self.datas_fname)
self.storage_backend_id._add_b64_data(path, self.datas)
def _get_failure_emails(self):
res = super()._get_failure_emails()
if self.task_id.failure_emails:
res = self.task_id.failure_emails
return res
@api.onchange("task_id")
def onchange_task_id(self):
for attachment in self:
if attachment.task_id.method_type == "export":
attachment.file_type = "export"

209
attachment_synchronize/models/attachment_synchronize_task.py

@ -0,0 +1,209 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime
import logging
import os
import odoo
from odoo import api, fields, models, tools
from odoo.osv import expression
_logger = logging.getLogger(__name__)
try:
# We use a jinja2 sandboxed environment to render mako templates.
# Note that the rendering does not cover all the mako syntax, in particular
# arbitrary Python statements are not accepted, and not all expressions are
# allowed: only "public" attributes (not starting with '_') of objects may
# be accessed.
# This is done on purpose: it prevents incidental or malicious execution of
# Python code that may break the security of the server.
from jinja2.sandbox import SandboxedEnvironment
mako_template_env = SandboxedEnvironment(
variable_start_string="${",
variable_end_string="}",
line_statement_prefix="%",
trim_blocks=True, # do not output newline after blocks
)
mako_template_env.globals.update(
{
"str": str,
"datetime": datetime,
"len": len,
"abs": abs,
"min": min,
"max": max,
"sum": sum,
"filter": filter,
"map": map,
"round": round,
}
)
except ImportError:
_logger.warning("jinja2 not available, templating features will not work!")
class AttachmentSynchronizeTask(models.Model):
_name = "attachment.synchronize.task"
_description = "Attachment synchronize task"
name = fields.Char(required=True)
method_type = fields.Selection(
[("import", "Import Task"), ("export", "Export Task")], required=True
)
pattern = fields.Char(
string="Selection Pattern",
help="Pattern used to select the files to be imported following the 'fnmatch' "
"special characters (e.g. '*.txt' to catch all the text files).\n"
"If empty, import all the files found in 'File Path'.",
)
filepath = fields.Char(
string="File Path", help="Path to imported/exported files in the Backend"
)
backend_id = fields.Many2one("storage.backend", string="Backend")
attachment_ids = fields.One2many("attachment.queue", "task_id", string="Attachment")
move_path = fields.Char(
string="Move Path", help="Imported File will be moved to this path"
)
new_name = fields.Char(
string="New Name",
help="Imported File will be renamed to this name.\n"
"New Name can use 'mako' template where 'obj' is the original file's name.\n"
"For instance : ${obj.name}-${obj.create_date}.csv",
)
after_import = fields.Selection(
selection=[
("rename", "Rename"),
("move", "Move"),
("move_rename", "Move & Rename"),
("delete", "Delete"),
],
help="Action after import a file",
)
file_type = fields.Selection(
selection=[],
string="File Type",
help="Used to fill the 'File Type' field in the imported 'Attachments Queues'."
"\nFurther operations will be realized on these Attachments Queues depending "
"on their 'File Type' value.",
)
enabled = fields.Boolean("Enabled", default=True)
avoid_duplicated_files = fields.Boolean(
string="Avoid importing duplicated files",
help="If checked, a file will not be imported if an Attachment Queue with the "
"same name already exists.",
)
failure_emails = fields.Char(
string="Failure Emails",
help="Used to fill the 'Failure Emails' field in the 'Attachments Queues' "
"related to this task.\nAn alert will be sent to these emails if any operation "
"on these Attachment Queue's file type fails.",
)
def _prepare_attachment_vals(self, data, filename):
self.ensure_one()
vals = {
"name": filename,
"datas": data,
"datas_fname": filename,
"task_id": self.id,
"file_type": self.file_type or False,
}
return vals
@api.model
def _template_render(self, template, record):
try:
template = mako_template_env.from_string(tools.ustr(template))
except Exception:
_logger.exception("Failed to load template '{}'".format(template))
variables = {"obj": record}
try:
render_result = template.render(variables)
except Exception:
_logger.exception(
"Failed to render template '{}'' using values '{}'".format(
template, variables
)
)
render_result = u""
if render_result == u"False":
render_result = u""
return render_result
@api.model
def run_task_import_scheduler(self, domain=None):
if domain is None:
domain = []
domain = expression.AND(
[domain, [("method_type", "=", "import"), ("enabled", "=", True)]]
)
for task in self.search(domain):
task.run_import()
def run_import(self):
self.ensure_one()
attach_obj = self.env["attachment.queue"]
backend = self.backend_id
filepath = self.filepath or ""
filenames = backend._list(relative_path=filepath, pattern=self.pattern)
if self.avoid_duplicated_files:
filenames = self._file_to_import(filenames)
total_import = 0
for file_name in filenames:
with api.Environment.manage():
with odoo.registry(self.env.cr.dbname).cursor() as new_cr:
new_env = api.Environment(new_cr, self.env.uid, self.env.context)
try:
full_absolute_path = os.path.join(filepath, file_name)
data = backend._get_b64_data(full_absolute_path)
attach_vals = self._prepare_attachment_vals(data, file_name)
attachment = attach_obj.with_env(new_env).create(attach_vals)
new_full_path = False
if self.after_import == "rename":
new_name = self._template_render(self.new_name, attachment)
new_full_path = os.path.join(filepath, new_name)
elif self.after_import == "move":
new_full_path = os.path.join(self.move_path, file_name)
elif self.after_import == "move_rename":
new_name = self._template_render(self.new_name, attachment)
new_full_path = os.path.join(self.move_path, new_name)
if new_full_path:
backend._add_b64_data(new_full_path, data)
if self.after_import in (
"delete",
"rename",
"move",
"move_rename",
):
backend._delete(full_absolute_path)
total_import += 1
except Exception as e:
new_env.cr.rollback()
raise e
else:
new_env.cr.commit()
_logger.info("Run import complete! Imported {0} files".format(total_import))
def _file_to_import(self, filenames):
imported = (
self.env["attachment.queue"]
.search([("name", "in", filenames)])
.mapped("name")
)
return list(set(filenames) - set(imported))
def run_export(self):
for task in self:
task.attachment_ids.filtered(lambda a: a.state == "pending").run()
def button_toogle_enabled(self):
for rec in self:
rec.enabled = not rec.enabled
def button_duplicate_record(self):
self.ensure_one()
self.copy({"enabled": False})

67
attachment_synchronize/models/storage_backend.py

@ -0,0 +1,67 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class StorageBackend(models.Model):
_inherit = "storage.backend"
synchronize_task_ids = fields.One2many(
"attachment.synchronize.task", "backend_id", string="Tasks"
)
import_task_count = fields.Integer(
"Import Tasks", compute="_compute_import_task_count"
)
export_task_count = fields.Integer(
"Export Tasks", compute="_compute_export_task_count"
)
def _compute_import_task_count(self):
for rec in self:
rec.import_task_count = len(
rec.synchronize_task_ids.filtered(lambda t: t.method_type == "import")
)
def _compute_export_task_count(self):
for rec in self:
rec.export_task_count = len(
rec.synchronize_task_ids.filtered(lambda t: t.method_type == "export")
)
def action_related_import_task(self):
self.ensure_one()
act_window_xml_id = "attachment_synchronize.action_attachment_import_task"
act_window = self.env.ref(act_window_xml_id).read()[0]
domain = [
("id", "in", self.synchronize_task_ids.ids),
("method_type", "=", "import"),
]
act_window["domain"] = domain
if self.import_task_count == 1:
form = self.env.ref("attachment_synchronize.view_attachment_task_form")
act_window["views"] = [(form.id, "form")]
act_window["res_id"] = (
self.env["attachment.synchronize.task"].search(domain).id
)
return act_window
def action_related_export_task(self):
self.ensure_one()
act_window_xml_id = "attachment_synchronize.action_attachment_export_task"
act_window = self.env.ref(act_window_xml_id).read()[0]
domain = [
("id", "in", self.synchronize_task_ids.ids),
("method_type", "=", "export"),
]
act_window["domain"] = domain
if self.export_task_count == 1:
form = self.env.ref("attachment_synchronize.view_attachment_task_form")
act_window["views"] = [(form.id, "form")]
act_window["res_id"] = (
self.env["attachment.synchronize.task"].search(domain).id
)
return act_window

10
attachment_synchronize/readme/CONTRIBUTORS.rst

@ -0,0 +1,10 @@
`Akretion <https://www.akretion.com/>`_ :
- Valentin CHEMIERE
- Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
- Florian DA COSTA <florian.dacosta@akretion.com>
- Clément MOMBEREAU <clement.mombereau@akretion.com.br>
GS Lab:
- Giovanni SERRA <giovanni@gslab.it>

5
attachment_synchronize/readme/DESCRIPTION.rst

@ -0,0 +1,5 @@
This module allows to **import/export files** from/to backend servers.
A backend server is defined by the basic `storage_backend <https://github.com/OCA/storage/tree/12.0/storage_backend>`_ OCA module, while it can be configured (amazon S3, sftp,...) with additional modules from the `storage <https://github.com/oca/storage>`_ repository.
The imported files (and the files to be exported) are stored in Odoo as ``attachment.queue`` objects, defined by the `attachment_queue <https://github.com/OCA/server-tools/tree/12.0/attachment_queue>`_ module while the importation itself (resp. exportation) is realized by **"Attachments Import Tasks"** (resp. "Attachments Export Tasks") defined by this current module.

19
attachment_synchronize/readme/USAGE.rst

@ -0,0 +1,19 @@
As importation and exportation are different processes, they are triggered in different ways :
**To import files**, you need to create an *"Attachment Import Task"* (menu *Settings > Technical > Attachments Import Tasks*) which defines :
- where to find the files to import from the backend server (path to the files, selection pattern)
- what to do with the source files in the backend server (avoid duplicates, delete/rename after import...)
- how the files will be processed once imported (through the **File Type** field).
.. image:: ../static/description/import_task.png
.. epigraph::
🔎 The **File Type** options are defined by other modules built to process the Attachments Queues with the same "File Type".
**To export files**, you need first to register them as *"Attachments Queues"* objects linked to an *"Attachment Export Task"* (which set automatically their **File Type** to *"Export File (External Location)"*).
Then, you can export one file at a time from the *Attachment Queue*'s form view, or export all the *Attachments Queues* in a pending state related to the same *Export Task* from the given *Export Task* form view (menu *Settings > Technical > Attachments Export Tasks*) :
.. image:: ../static/description/export_task.png

2
attachment_synchronize/security/ir.model.access.csv

@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_attachment_synchronize_task_manager,attachment.synchronize.task.manager,model_attachment_synchronize_task,base.group_system,1,1,1,1

BIN
attachment_synchronize/static/description/export_task.png

After

Width: 1281  |  Height: 616  |  Size: 61 KiB

BIN
attachment_synchronize/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

BIN
attachment_synchronize/static/description/import_task.png

After

Width: 1296  |  Height: 585  |  Size: 68 KiB

448
attachment_synchronize/static/description/index.html

@ -0,0 +1,448 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Attachment Synchronize</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="attachment-synchronize">
<h1 class="title">Attachment Synchronize</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-tools/tree/12.0/attachment_synchronize"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-attachment_synchronize"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/149/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to <strong>import/export files</strong> from/to backend servers.</p>
<p>A backend server is defined by the basic <a class="reference external" href="https://github.com/OCA/storage/tree/12.0/storage_backend">storage_backend</a> OCA module, while it can be configured (amazon S3, sftp,…) with additional modules from the <a class="reference external" href="https://github.com/oca/storage">storage</a> repository.</p>
<p>The imported files (and the files to be exported) are stored in Odoo as <tt class="docutils literal">attachment.queue</tt> objects, defined by the <a class="reference external" href="https://github.com/OCA/server-tools/tree/12.0/attachment_queue">attachment_queue</a> module while the importation itself (resp. exportation) is realized by <strong>“Attachments Import Tasks”</strong> (resp. “Attachments Export Tasks”) defined by this current module.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>As importation and exportation are different processes, they are triggered in different ways :</p>
<p><strong>To import files</strong>, you need to create an <em>“Attachment Import Task”</em> (menu <em>Settings &gt; Technical &gt; Attachments Import Tasks</em>) which defines :</p>
<ul class="simple">
<li>where to find the files to import from the backend server (path to the files, selection pattern)</li>
<li>what to do with the source files in the backend server (avoid duplicates, delete/rename after import…)</li>
<li>how the files will be processed once imported (through the <strong>File Type</strong> field).</li>
</ul>
<img alt="https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/import_task.png" src="https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/import_task.png" />
<blockquote class="epigraph">
🔎 The <strong>File Type</strong> options are defined by other modules built to process the Attachments Queues with the same “File Type”.</blockquote>
<p><strong>To export files</strong>, you need first to register them as <em>“Attachments Queues”</em> objects linked to an <em>“Attachment Export Task”</em> (which set automatically their <strong>File Type</strong> to <em>“Export File (External Location)”</em>).</p>
<p>Then, you can export one file at a time from the <em>Attachment Queue</em>’s form view, or export all the <em>Attachments Queues</em> in a pending state related to the same <em>Export Task</em> from the given <em>Export Task</em> form view (menu <em>Settings &gt; Technical &gt; Attachments Export Tasks</em>) :</p>
<img alt="https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/export_task.png" src="https://raw.githubusercontent.com/OCA/server-tools/12.0/attachment_synchronize/static/description/export_task.png" />
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20attachment_synchronize%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<p><a class="reference external" href="https://www.akretion.com/">Akretion</a> :</p>
<ul class="simple">
<li>Valentin CHEMIERE</li>
<li>Mourad EL HADJ MIMOUNE &lt;<a class="reference external" href="mailto:mourad.elhadj.mimoune&#64;akretion.com">mourad.elhadj.mimoune&#64;akretion.com</a>&gt;</li>
<li>Florian DA COSTA &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
<li>Clément MOMBEREAU &lt;<a class="reference external" href="mailto:clement.mombereau&#64;akretion.com.br">clement.mombereau&#64;akretion.com.br</a>&gt;</li>
</ul>
<p>GS Lab:</p>
<ul class="simple">
<li>Giovanni SERRA &lt;<a class="reference external" href="mailto:giovanni&#64;gslab.it">giovanni&#64;gslab.it</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/florian-dacosta"><img alt="florian-dacosta" src="https://github.com/florian-dacosta.png?size=40px" /></a> <a class="reference external" href="https://github.com/GSLabIt"><img alt="GSLabIt" src="https://github.com/GSLabIt.png?size=40px" /></a> <a class="reference external" href="https://github.com/bealdav"><img alt="bealdav" src="https://github.com/bealdav.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/12.0/attachment_synchronize">OCA/server-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

2
attachment_synchronize/tests/__init__.py

@ -0,0 +1,2 @@
from . import test_import
from . import test_export

43
attachment_synchronize/tests/common.py

@ -0,0 +1,43 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
import os
from odoo.addons.storage_backend.tests.common import Common
class SyncCommon(Common):
def _clean_testing_directory(self):
for test_dir in [
self.directory_input,
self.directory_output,
self.directory_archived,
]:
for filename in self.backend._list(test_dir):
self.backend._delete(os.path.join(test_dir, filename))
def _create_test_file(self):
self.backend._add_b64_data(
os.path.join(self.directory_input, "bar.txt"),
self.filedata,
mimetype=u"text/plain",
)
def setUp(self):
super().setUp()
self.env.cr.commit = mock.Mock()
self.registry.enter_test_mode(self.env.cr)
self.directory_input = "test_import"
self.directory_output = "test_export"
self.directory_archived = "test_archived"
self._clean_testing_directory()
self._create_test_file()
self.task = self.env.ref(
"attachment_synchronize.import_from_filestore"
)
def tearDown(self):
self.registry.leave_test_mode()
self._clean_testing_directory()
super().tearDown()

42
attachment_synchronize/tests/test_export.py

@ -0,0 +1,42 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
from .common import SyncCommon
from odoo.tools import mute_logger
def raising_side_effect(*args, **kwargs):
raise Exception("Boom")
class TestExport(SyncCommon):
def setUp(self):
super().setUp()
self.task = self.env.ref("attachment_synchronize.export_to_filestore")
self.attachment = self.env["attachment.queue"].create(
{
"name": "foo.txt",
"datas_fname": "foo.txt",
"task_id": self.task.id,
"file_type": "export",
"datas": self.filedata,
}
)
def test_export(self):
self.attachment.run()
result = self.backend._list("test_export")
self.assertEqual(result, ["foo.txt"])
@mute_logger("odoo.addons.attachment_queue.models.attachment_queue")
def test_failing_export(self):
with mock.patch.object(
type(self.backend),
"_add_b64_data",
side_effect=raising_side_effect,
):
self.attachment.run()
self.assertEqual(self.attachment.state, "failed")
self.assertEqual(self.attachment.state_message, "Boom")

83
attachment_synchronize/tests/test_import.py

@ -0,0 +1,83 @@
# Copyright 2020 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from .common import SyncCommon
class TestImport(SyncCommon):
@property
def archived_files(self):
return self.backend._list(self.directory_archived)
@property
def input_files(self):
return self.backend._list(self.directory_input)
def _check_attachment_created(self, count=1):
attachment = self.env["attachment.queue"].search([("name", "=", "bar.txt")])
self.assertEqual(len(attachment), count)
def test_import_with_rename(self):
self.task.write({"after_import": "rename", "new_name": "foo.txt"})
self.task.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, ["foo.txt"])
self.assertEqual(self.archived_files, [])
def test_import_with_move(self):
self.task.write({"after_import": "move", "move_path": self.directory_archived})
self.task.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, ["bar.txt"])
def test_import_with_move_and_rename(self):
self.task.write(
{
"after_import": "move_rename",
"new_name": "foo.txt",
"move_path": self.directory_archived,
}
)
self.task.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, ["foo.txt"])
def test_import_with_delete(self):
self.task.write({"after_import": "delete"})
self.task.run_import()
self._check_attachment_created()
self.assertEqual(self.input_files, [])
self.assertEqual(self.archived_files, [])
def test_import_twice(self):
self.task.write({"after_import": "delete"})
self.task.run_import()
self._check_attachment_created(count=1)
self._create_test_file()
self.task.run_import()
self._check_attachment_created(count=2)
def test_import_twice_no_duplicate(self):
self.task.write(
{"after_import": "delete", "avoid_duplicated_files": True}
)
self.task.run_import()
self._check_attachment_created(count=1)
self._create_test_file()
self.task.run_import()
self._check_attachment_created(count=1)
def test_running_cron(self):
self.task.write({"after_import": "delete"})
self.env["attachment.synchronize.task"].run_task_import_scheduler()
self._check_attachment_created(count=1)
def test_running_cron_disable_task(self):
self.task.write({"after_import": "delete", "enabled": False})
self.env["attachment.synchronize.task"].run_task_import_scheduler()
self._check_attachment_created(count=0)

35
attachment_synchronize/views/attachment_queue_views.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_attachment_queue_form" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="inherit_id" ref="attachment_queue.view_attachment_queue_form" />
<field name="arch" type="xml">
<!-- Add Related Task and Backend -->
<xpath expr="//field[@name='url']" position="after">
<field name="method_type" invisible="1"/>
<field
name="task_id"
domain="[('method_type', '!=', 'import')]"
attrs="{'required': [('file_type', '=', 'export')], 'readonly': [('method_type', '=', 'import')]}"
/>
<field name="storage_backend_id"/>
</xpath>
</field>
</record>
<record id="view_attachment_queue_tree" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="inherit_id" ref="attachment_queue.view_attachment_queue_tree" />
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="decoration-muted">state == 'done'</attribute>
</xpath>
<xpath expr="//field[@name='file_type']" position="after">
<field name="task_id"/>
<field name="storage_backend_id"/>
</xpath>
</field>
</record>
</odoo>

177
attachment_synchronize/views/attachment_synchronize_task_views.xml

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_attachment_task_form" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<form>
<header>
<button name="run_import" type="object" string="Run Import" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'import'), ('enabled','=', False)]}"/>
</header>
<header>
<button name="run_export" type="object" string="Run Export" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'export'), ('enabled','=', False)]}"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="button_toogle_enabled" type="object" class="oe_stat_button" icon="fa-archive">
<field
name="enabled"
widget="boolean_button"
options="{'terminology': {
'string_true': 'Enabled',
'hover_true': &quot;Disable&quot;,
'string_false': 'Disabled',
'hover_false': &quot;Enable&quot;,
}}"
/>
</button>
</div>
<field name="method_type" invisible="1"/>
<div class="oe_title">
<label class="oe_edit_only" for="name" string="Name"/>
<h1>
<field name="name" class="oe_inline"/>
</h1>
<field name="create_date" invisible="1" />
<field name="method_type" widget="radio" options="{'horizontal': true}" attrs="{'readonly':[('create_date', '!=', False)]}"/>
</div>
<group string="Storage Location" class="col-12 col-lg-6">
<field name="backend_id"/>
<field name="filepath"/>
<field name="pattern" attrs="{'invisible':[('method_type','!=','import')]}"/>
</group>
<group name="action" string="Importation" attrs="{'invisible':[('method_type','!=','import')]}" class="col-12 col-lg-6">
<field name="avoid_duplicated_files" />
<field name="after_import" />
<field name="move_path" colspan="4" attrs="{'invisible':[('after_import','!=','move'), ('after_import','!=','move_rename')]}"/>
<field name="new_name" colspan="4" attrs="{'invisible': [('after_import','!=','rename'), ('after_import','!=','move_rename')]}"/>
</group>
<group string="Attachments">
<group>
<field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}" />
<field name="failure_emails" />
</group>
<field name="attachment_ids" domain="[('task_id', '=', id)]" nolabel="1" attrs="{'invisible':[('method_type','!=','export')]}">
<tree>
<field name="name"/>
<field name="datas_fname"/>
<field name="file_type"/>
<field name="storage_backend_id"/>
<field name="type"/>
<field name="create_date"/>
<field name="state"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_attachment_import_task_tree" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<tree string="Tasks" decoration-muted="enabled == False">
<field name="name" select="1"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="pattern"/>
<field name="after_import"/>
<field name="move_path"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
</tree>
</field>
</record>
<record id="view_attachment_export_task_tree" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<tree string="Tasks" decoration-muted="enabled == False">
<field name="name" select="1"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone"/>
<button name="button_toogle_enabled" type="object" string="Enable" icon="fa-archive"/>
</tree>
</field>
</record>
<record id="view_attachment_task_search" model="ir.ui.view">
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<search string="Attachments">
<field name="name" filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]" string="Attachment Task"/>
<field name="create_date"/>
<filter string="Backend" name="backend" context="{'group_by':'backend_id'}"/>
</search>
</field>
</record>
<!-- Attachments Import Tasks Menu -->
<record id="action_attachment_import_task" model="ir.actions.act_window">
<field name="name">Attachments Import Tasks</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">attachment.synchronize.task</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_attachment_task_search"/>
<field name="domain">[('method_type', '=', 'import')]</field>
<field name="context">{'default_method_type': 'import'}</field>
</record>
<record id="act_open_attachment_import_task_view_tree" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_attachment_import_task_tree"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
<record id="act_open_attachment_import_task_view_form" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_task_form"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
<menuitem id="menu_attachment_import_task"
parent="base.next_id_9"
sequence="21"
action="action_attachment_import_task"/>
<!-- Attachments Export Tasks Menu -->
<record id="action_attachment_export_task" model="ir.actions.act_window">
<field name="name">Attachments Export Tasks</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">attachment.synchronize.task</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_attachment_task_search"/>
<field name="domain">[('method_type', '=', 'export')]</field>
<field name="context">{'default_method_type': 'export'}</field>
</record>
<record id="act_open_attachment_export_task_view_tree" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_attachment_export_task_tree"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
</record>
<record id="act_open_attachment_export_task_view_form" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_task_form"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
</record>
<menuitem id="menu_attachment_export_task"
parent="base.next_id_9"
sequence="22"
action="action_attachment_export_task"/>
</odoo>

34
attachment_synchronize/views/storage_backend_views.xml

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_storage_backend_form" model="ir.ui.view">
<field name="model">storage.backend</field>
<field name="inherit_id" ref="storage_backend.storage_backend_view_form" />
<field name="priority" eval="250"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_title')]" position="before">
<div class="oe_button_box" name="button_box">
<button
class="oe_stat_button"
type="object"
attrs="{'invisible': [('import_task_count', '&lt;', 1)]}"
name="action_related_import_task"
icon="fa-download"
>
<field name="import_task_count" widget="statinfo" />
</button>
<button
class="oe_stat_button"
type="object"
attrs="{'invisible': [('export_task_count', '&lt;', 1)]}"
name="action_related_export_task"
icon="fa-upload"
>
<field name="export_task_count" widget="statinfo" />
</button>
</div>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save