Browse Source

- better view layout

- match pattern filename to download
- empty list as default domain
12.0-mig-module_prototyper_last
Giovanni 5 years ago
committed by David Beal
parent
commit
8c8a866216
  1. 22
      attachment_synchronize/models/task.py
  2. 36
      attachment_synchronize/views/attachment_view.xml
  3. 17
      attachment_synchronize/views/storage_backend_view.xml
  4. 44
      attachment_synchronize/views/task_view.xml

22
attachment_synchronize/models/task.py

@ -1,12 +1,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api
import odoo
from odoo import tools
from base64 import b64encode
import os
import datetime import datetime
import logging import logging
import os
from fnmatch import fnmatch
import odoo
from odoo import api, fields, models, tools
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -112,10 +112,10 @@ class StorageTask(models.Model):
return render_result return render_result
@api.model @api.model
def run_task_scheduler(self, domain=None):
if domain is None:
domain = []
domain.append([('method_type', '=', 'import')])
def run_task_scheduler(self, domain=list()):
if ('method_type', '=', 'import') not in domain:
domain.append([('method_type', '=', 'import')])
tasks = self.env['storage.backend'].search(domain) tasks = self.env['storage.backend'].search(domain)
for task in tasks: for task in tasks:
task.run_import() task.run_import()
@ -127,7 +127,7 @@ class StorageTask(models.Model):
backend = self.backend_id backend = self.backend_id
all_filenames = backend._list(relative_path=self.filepath) all_filenames = backend._list(relative_path=self.filepath)
if self.filename: if self.filename:
filenames = [x for x in all_filenames if self.filename in x]
filenames = [x for x in all_filenames if fnmatch(x, self.filename)]
for file_name in filenames: for file_name in filenames:
with api.Environment.manage(): with api.Environment.manage():
with odoo.registry( with odoo.registry(
@ -160,7 +160,7 @@ class StorageTask(models.Model):
backend._add_b64_data(new_full_path, datas) backend._add_b64_data(new_full_path, datas)
if self.after_import in ( if self.after_import in (
'delete', 'rename', 'move', 'move_rename' 'delete', 'rename', 'move', 'move_rename'
):
):
backend._delete(full_absolute_path) backend._delete(full_absolute_path)
except Exception as e: except Exception as e:
new_env.cr.rollback() new_env.cr.rollback()

36
attachment_synchronize/views/attachment_view.xml

@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<odoo> <odoo>
<record id="view_attachment_improved_form" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="inherit_id" ref="base_attachment_queue.view_attachment_improved_form" />
<field name="arch" type="xml">
<field name="url" position="after">
<field name="task_id" attrs="{'required': [('file_type', '=', 'export')]}"/>
<field name="storage_backend_id"/>
</field>
<record id="view_attachment_improved_form" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="inherit_id" ref="base_attachment_queue.view_attachment_improved_form" />
<field name="arch" type="xml">
<field name="url" position="after">
<field name="task_id" attrs="{'required': [('file_type', '=', 'export')]}"/>
<field name="storage_backend_id"/>
</field> </field>
</record>
</field>
</record>
<record id="view_external_attachment_tree" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="inherit_id" ref="base_attachment_queue.view_external_attachment_tree" />
<field name="arch" type="xml">
<field name="file_type" position="after">
<field name="task_id"/>
<field name="storage_backend_id"/>
</field>
<record id="view_external_attachment_tree" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="inherit_id" ref="base_attachment_queue.view_external_attachment_tree" />
<field name="arch" type="xml">
<field name="file_type" position="after">
<field name="task_id"/>
<field name="storage_backend_id"/>
</field> </field>
</record>
</field>
</record>
</odoo> </odoo>

17
attachment_synchronize/views/storage_backend_view.xml

@ -3,15 +3,16 @@
<record id="view_storage_backend_form" model="ir.ui.view"> <record id="view_storage_backend_form" model="ir.ui.view">
<field name="model">storage.backend</field> <field name="model">storage.backend</field>
<field name="inherit_id" ref="storage_backend.storage_backend_view_form" />
<field name="priority" eval="250"/>
<field name="inherit_id" ref="storage_backend.storage_backend_view_form" />
<field name="priority" eval="250"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form>
<xpath expr="/form/sheet" position="inside">
<separator string="Tasks"/>
<field name="task_ids" nolabel="1"/>
</xpath>
</form>
<xpath expr="//group[@name='config']" position="after">
<notebook>
<page string="Tasks">
<field name="task_ids"/>
</page>
</notebook>
</xpath>
</field> </field>
</record> </record>

44
attachment_synchronize/views/task_view.xml

@ -1,40 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<odoo> <odoo>
<record id="view_task_form" model="ir.ui.view"> <record id="view_task_form" model="ir.ui.view">
<field name="model">storage.backend.task</field> <field name="model">storage.backend.task</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<header> <header>
<button name="run_import" type="object" string="Run" icon="gtk-execute" attrs="{'invisible': [('method_type', '!=', 'import')]}"/>
<button name="run_import" type="object" string="Run" class="oe_read_only" icon="fa-play-circle" attrs="{'invisible': ['|', ('method_type', '!=', 'import'), ('enabled','=', False)]}"/>
</header> </header>
<sheet> <sheet>
<field name="method_type" invisible="1"/> <field name="method_type" invisible="1"/>
<group col="4">
<div class="oe_title" style="width: 390px;" colspan="4">
<label class="oe_edit_only" for="name" string="Name"/>
<h1><field name="name" class="oe_inline"/></h1>
</div>
<field name="method_type" colspan="2"/>
<span colspan="2"/>
<field name="filename" colspan="4" attrs="{'invisible':[('method_type','!=','import')]}"/>
<field name="filepath" colspan="4" />
<div class="oe_title" style="width: 390px;" colspan="4">
<label class="oe_edit_only" for="name" string="Name"/>
<h2>
<field name="name" class="oe_inline"/>
</h2>
</div>
<group>
<field name="enabled"/>
<field name="method_type"/>
<field name="filename" attrs="{'invisible':[('method_type','!=','import')]}"/>
<field name="filepath"/>
</group> </group>
<group col="6">
<group name="action" string="Action">
<field name="after_import" attrs="{'invisible':[('method_type','!=','import')]}"/> <field name="after_import" attrs="{'invisible':[('method_type','!=','import')]}"/>
<group col="4" colspan="4" >
<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>
<field name="active" colspan="2"/>
<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>
<group string="Data importation setting"> <group string="Data importation setting">
<field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}"/> <field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}"/>
@ -47,10 +37,10 @@
<record id="view_task_tree" model="ir.ui.view"> <record id="view_task_tree" model="ir.ui.view">
<field name="model">storage.backend.task</field> <field name="model">storage.backend.task</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Tasks" >
<tree string="Tasks">
<field name="name" select="1"/> <field name="name" select="1"/>
<field name="method_type"/> <field name="method_type"/>
<field name="filename"/>
<field name="filename"/>
<field name="filepath"/> <field name="filepath"/>
</tree> </tree>
</field> </field>

Loading…
Cancel
Save