Browse Source

[IMP] attachment_synchronize: rename files + add buttonbox task enabled

12.0-mig-module_prototyper_last
clementmbr 4 years ago
committed by David Beal
parent
commit
cd54fba093
  1. 6
      attachment_synchronize/__manifest__.py
  2. 4
      attachment_synchronize/models/__init__.py
  3. 0
      attachment_synchronize/models/attachment_queue.py
  4. 49
      attachment_synchronize/models/attachment_synchronize_task.py
  5. 0
      attachment_synchronize/views/attachment_queue_views.xml
  6. 70
      attachment_synchronize/views/attachment_synchronize_task_views.xml
  7. 0
      attachment_synchronize/views/storage_backend_views.xml

6
attachment_synchronize/__manifest__.py

@ -12,9 +12,9 @@
"category": "Generic Modules",
"depends": ["attachment_queue", "storage_backend"],
"data": [
"views/attachment_view.xml",
"views/task_view.xml",
"views/storage_backend_view.xml",
"views/attachment_queue_views.xml",
"views/attachment_synchronize_task_views.xml",
"views/storage_backend_views.xml",
"data/cron.xml",
"security/ir.model.access.csv",
],

4
attachment_synchronize/models/__init__.py

@ -1,3 +1 @@
from . import attachment
from . import task
from . import storage_backend
from . import attachment_queue, attachment_synchronize_task, storage_backend

0
attachment_synchronize/models/attachment.py → attachment_synchronize/models/attachment_queue.py

49
attachment_synchronize/models/task.py → attachment_synchronize/models/attachment_synchronize_task.py

@ -59,13 +59,11 @@ class AttachmentSynchronizeTask(models.Model):
"least contains the pattern in its name. "
"Leave it empty to import all files"
)
filepath = fields.Char(help="Path to imported/exported files in the Backend")
backend_id = fields.Many2one(
"storage.backend", string="Backend", required=True
)
attachment_ids = fields.One2many(
"attachment.queue", "task_id", string="Attachment"
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"
)
@ -102,6 +100,10 @@ class AttachmentSynchronizeTask(models.Model):
"when excuting the files linked to this task",
)
def toogle_enabled(self):
for task in self:
task.enabled = not task.enabled
def _prepare_attachment_vals(self, data, filename):
self.ensure_one()
vals = {
@ -125,8 +127,7 @@ class AttachmentSynchronizeTask(models.Model):
render_result = template.render(variables)
except Exception:
_logger.exception(
"Failed to render template %r using values %r"
% (template, variables)
"Failed to render template %r using values %r" % (template, variables)
)
render_result = u""
if render_result == u"False":
@ -155,35 +156,21 @@ class AttachmentSynchronizeTask(models.Model):
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
)
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
)
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_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
)
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
)
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 (
@ -199,9 +186,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 {0} files".format(total_import))
def _file_to_import(self, filenames):
imported = (

0
attachment_synchronize/views/attachment_view.xml → attachment_synchronize/views/attachment_queue_views.xml

70
attachment_synchronize/views/task_view.xml → attachment_synchronize/views/attachment_synchronize_task_views.xml

@ -5,9 +5,23 @@
<field name="arch" type="xml">
<form>
<header>
<button name="run_import" type="object" string="Run Import" class="oe_read_only" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'import'), ('enabled','=', False)]}"/>
<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>
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toogle_enabled" type="object" class="oe_stat_button" icon="fa-check-square">
<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" colspan="4">
<label class="oe_edit_only" for="name" string="Name"/>
@ -17,22 +31,21 @@
</div>
<div class="col-12 col-lg-6">
<group>
<field name="enabled"/>
<!-- <field name="enabled"/> -->
<field name="method_type"/>
<field name="pattern" attrs="{'invisible':[('method_type','!=','import')]}"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="backend_id" attrs="{'invisible':[('method_type','!=','import')]}"/>
</group>
<group name="action" string="Action">
<field name="emails"/>
<field name="after_import" attrs="{'invisible':[('method_type','!=','import')]}"/>
<field name="move_path" colspan="4" attrs="{'invisible':['|', '&amp;', ('after_import','!=','move'), ('after_import','!=','move_rename'), ('method_type','!=','import')]}"/>
<field name="new_name" colspan="4" attrs="{'invisible': ['|', '&amp;', ('after_import','!=','rename'), ('after_import','!=','move_rename'), ('method_type','!=','import')]}"/>
</group>
<group string="Data importation settings" attrs="{'invisible':[('method_type','!=','import')]}" >
<field name="check_duplicated_files" />
<field name="file_type" />
<field name="check_duplicated_files" />
</group>
</div>
</sheet>
@ -45,7 +58,6 @@
<field name="arch" type="xml">
<tree string="Tasks" decoration-muted="enabled == False">
<field name="name" select="1"/>
<field name="method_type"/>
<field name="pattern"/>
<field name="filepath"/>
<field name="move_path"/>
@ -69,33 +81,67 @@
</field>
</record>
<record id="action_attachment_task" model="ir.actions.act_window">
<field name="name">Attachments Tasks</field>
<!-- 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>
</record>
<record id="act_open_attachment_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_task_tree"/>
<field name="act_window_id" ref="action_attachment_task"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
<record id="act_open_attachment_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_task"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
<menuitem id="menu_attachment_task"
<menuitem id="menu_attachment_import_task"
parent="base.next_id_9"
sequence="21"
action="action_attachment_task"/>
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>
</record>
<record id="act_open_attachment_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_task_tree"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
</record>
<record id="act_open_attachment_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>

0
attachment_synchronize/views/storage_backend_view.xml → attachment_synchronize/views/storage_backend_views.xml

Loading…
Cancel
Save