[IMP] attachment_synchronize: pre-commit

pull/2632/head
Kevin Khao 2021-03-04 12:13:18 +01:00 committed by Florian da Costa
parent e976d63216
commit 3ef953ad91
11 changed files with 199 additions and 90 deletions

View File

@ -7,7 +7,7 @@
"name": "Attachment Synchronize",
"version": "12.0.2.0.0",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/oca/server-tools",
"website": "https://github.com/OCA/server-tools",
"maintainers": ["florian-dacosta", "sebastienbeau", "GSLabIt", "bealdav"],
"license": "AGPL-3",
"category": "Generic Modules",

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record model="ir.cron" id="cronjob_run_attachment_synchronize_task_import">
@ -8,7 +8,7 @@
<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="model_id" ref="model_attachment_synchronize_task" />
<field name="state">code</field>
<field name="code">model.run_task_import_scheduler()</field>
</record>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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="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>
@ -10,7 +10,7 @@
<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="backend_id" ref="storage_backend.default_storage_backend" />
<field name="method_type">export</field>
<field name="filepath">test_export</field>
</record>

View File

@ -2,7 +2,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os
from odoo import api, models, fields
from odoo import api, fields, models
class AttachmentQueue(models.Model):

View File

@ -108,8 +108,9 @@ class AttachmentSynchronizeTask(models.Model):
def _compute_count_state(self):
for record in self:
for state in ["failed", "pending", "done"]:
record["count_attachment_{}".format(state)] = \
len(record.attachment_ids.filtered(lambda r: r.state == state))
record["count_attachment_{}".format(state)] = len(
record.attachment_ids.filtered(lambda r: r.state == state)
)
def _prepare_attachment_vals(self, data, filename):
self.ensure_one()
@ -138,18 +139,16 @@ class AttachmentSynchronizeTask(models.Model):
template, variables
)
)
render_result = u""
if render_result == u"False":
render_result = u""
render_result = ""
if render_result == "False":
render_result = ""
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")]]
)
domain = expression.AND([domain, [("method_type", "=", "import")]])
for task in self.search(domain):
task.run_import()
@ -203,7 +202,7 @@ class AttachmentSynchronizeTask(models.Model):
raise e
else:
new_env.cr.commit()
_logger.info("Run import complete! Imported {0} files".format(total_import))
_logger.info("Run import complete! Imported {} files".format(total_import))
def _file_to_import(self, filenames):
imported = (

View File

@ -2,8 +2,10 @@
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
import os
import mock
from odoo.addons.storage_backend.tests.common import Common
@ -21,7 +23,7 @@ class SyncCommon(Common):
self.backend._add_b64_data(
os.path.join(self.directory_input, "bar.txt"),
self.filedata,
mimetype=u"text/plain",
mimetype="text/plain",
)
def setUp(self):
@ -33,9 +35,7 @@ class SyncCommon(Common):
self.directory_archived = "test_archived"
self._clean_testing_directory()
self._create_test_file()
self.task = self.env.ref(
"attachment_synchronize.import_from_filestore"
)
self.task = self.env.ref("attachment_synchronize.import_from_filestore")
def tearDown(self):
self.registry.leave_test_mode()

View File

@ -3,9 +3,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import mock
from .common import SyncCommon
from odoo.tools import mute_logger
from .common import SyncCommon
def raising_side_effect(*args, **kwargs):
raise Exception("Boom")

View File

@ -62,9 +62,7 @@ class TestImport(SyncCommon):
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.write({"after_import": "delete", "avoid_duplicated_files": True})
self.task.run_import()
self._check_attachment_created(count=1)

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_attachment_queue_form" model="ir.ui.view">
@ -7,13 +7,13 @@
<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="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"/>
<field name="storage_backend_id" />
</xpath>
</field>
</record>
@ -26,18 +26,18 @@
<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"/>
<field name="task_id" />
<field name="storage_backend_id" />
</xpath>
</field>
</record>
<record id="attachment_queue_view_search" model="ir.ui.view">
<field name="model">attachment.queue</field>
<field name="inherit_id" ref="attachment_queue.view_attachment_queue_search"/>
<field name="inherit_id" ref="attachment_queue.view_attachment_queue_search" />
<field name="arch" type="xml">
<field name="type" position="after">
<field name="task_id" filter_domain="[('task_id.name','ilike',self)]"/>
<field name="task_id" filter_domain="[('task_id.name','ilike',self)]" />
</field>
</field>
</record>
@ -48,9 +48,12 @@
<field name="res_model">attachment.queue</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/>
<field name="view_id" eval="False" />
<field name="domain">[('task_id', '=', active_id)]</field>
<field name="search_view_id" ref="attachment_queue.view_attachment_queue_search"/>
<field
name="search_view_id"
ref="attachment_queue.view_attachment_queue_search"
/>
</record>
</odoo>

View File

@ -1,43 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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" type="object" string="Run" class="oe_read_only oe_highlight" icon="fa-play-circle" attrs="{'invisible': [('active','=', False)]}"/>
<button
name="run"
type="object"
string="Run"
class="oe_read_only oe_highlight"
icon="fa-play-circle"
attrs="{'invisible': [('active','=', False)]}"
/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-thumbs-o-down" context="{'search_default_failed': 1}">
<button
name="%(action_attachment_queue_related)d"
type="action"
class="oe_stat_button"
icon="fa-thumbs-o-down"
context="{'search_default_failed': 1}"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_failed" widget="statinfo" nolabel="1"/>
<field
name="count_attachment_failed"
widget="statinfo"
nolabel="1"
/>
</span>
<span class="o_stat_text">Fail</span>
</div>
</button>
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-spinner" context="{'search_default_pending': 1}">
<button
name="%(action_attachment_queue_related)d"
type="action"
class="oe_stat_button"
icon="fa-spinner"
context="{'search_default_pending': 1}"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_pending" widget="statinfo" nolabel="1"/>
<field
name="count_attachment_pending"
widget="statinfo"
nolabel="1"
/>
</span>
<span class="o_stat_text">Pending</span>
</div>
</button>
<button name="%(action_attachment_queue_related)d" type="action" class="oe_stat_button" icon="fa-thumbs-o-up" context="{'search_default_done': 1}">
<button
name="%(action_attachment_queue_related)d"
type="action"
class="oe_stat_button"
icon="fa-thumbs-o-up"
context="{'search_default_done': 1}"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="count_attachment_done" widget="statinfo" nolabel="1"/>
<field
name="count_attachment_done"
widget="statinfo"
nolabel="1"
/>
</span>
<span class="o_stat_text">Success</span>
</div>
</button>
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<button
name="toggle_active"
type="object"
class="oe_stat_button"
icon="fa-archive"
>
<field
name="active"
widget="boolean_button"
options="{'terminology': {
name="active"
widget="boolean_button"
options="{'terminology': {
'string_true': 'Enabled',
'hover_true': &quot;Disable&quot;,
'string_false': 'Disabled',
@ -46,29 +88,50 @@
/>
</button>
</div>
<field name="method_type" invisible="1"/>
<field name="method_type" invisible="1" />
<div class="oe_title">
<label class="oe_edit_only" for="name" string="Name"/>
<label class="oe_edit_only" for="name" string="Name" />
<h1>
<field name="name" class="oe_inline"/>
<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)]}"/>
<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')]}"/>
<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">
<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')]}"/>
<field name="file_type"/>
<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')]}"
/>
<field name="file_type" />
</group>
<group string="Notification">
<field name="failure_emails"/>
<field name="failure_emails" />
</group>
</sheet>
</form>
@ -79,19 +142,46 @@
<field name="model">attachment.synchronize.task</field>
<field name="arch" type="xml">
<tree string="Tasks" decoration-muted="active == False">
<field name="name" select="1"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="active" invisible="1"/>
<button name="run" type="object" string="Run" icon="fa-play-circle"/>
<field name="count_attachment_failed" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-thumbs-o-down" context="{'search_default_failed': 1}"/>
<field name="count_attachment_pending" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-spinner" context="{'search_default_pending': 1}"/>
<field name="count_attachment_done" string=" "/>
<button name="%(action_attachment_queue_related)d" type="action" icon="fa-thumbs-o-up" context="{'search_default_done': 1}"/>
<button name="button_duplicate_record" type="object" string="Copy" icon="fa-clone" invisible="not context.get('show_duplicate_button')"/>
<button name="toggle_active" type="object" string="Active/Inactive" icon="fa-archive" invisible="not context.get('show_toggle_active_button')"/>
<field name="name" select="1" />
<field name="backend_id" />
<field name="filepath" />
<field name="active" invisible="1" />
<button name="run" type="object" string="Run" icon="fa-play-circle" />
<field name="count_attachment_failed" string=" " />
<button
name="%(action_attachment_queue_related)d"
type="action"
icon="fa-thumbs-o-down"
context="{'search_default_failed': 1}"
/>
<field name="count_attachment_pending" string=" " />
<button
name="%(action_attachment_queue_related)d"
type="action"
icon="fa-spinner"
context="{'search_default_pending': 1}"
/>
<field name="count_attachment_done" string=" " />
<button
name="%(action_attachment_queue_related)d"
type="action"
icon="fa-thumbs-o-up"
context="{'search_default_done': 1}"
/>
<button
name="button_duplicate_record"
type="object"
string="Copy"
icon="fa-clone"
invisible="not context.get('show_duplicate_button')"
/>
<button
name="toggle_active"
type="object"
string="Active/Inactive"
icon="fa-archive"
invisible="not context.get('show_toggle_active_button')"
/>
</tree>
</field>
</record>
@ -100,9 +190,17 @@
<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'}"/>
<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>
@ -115,16 +213,20 @@
<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="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', "active_test": False}</field>
<field
name="context"
>{'default_method_type': 'import', "active_test": False}</field>
</record>
<menuitem id="menu_attachment_import_task"
parent="base.next_id_9"
sequence="21"
action="action_attachment_import_task"/>
<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">
@ -133,15 +235,19 @@
<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="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', "active_test": False}</field>
<field
name="context"
>{'default_method_type': 'export', "active_test": False}</field>
</record>
<menuitem id="menu_attachment_export_task"
parent="base.next_id_9"
sequence="22"
action="action_attachment_export_task"/>
<menuitem
id="menu_attachment_export_task"
parent="base.next_id_9"
sequence="22"
action="action_attachment_export_task"
/>
</odoo>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?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="priority" eval="250" />
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_title')]" position="before">
<div class="oe_button_box" name="button_box">