Browse Source

[IMP] rename check_duplicated_files and improve Task views

12.0-mig-module_prototyper_last
clementmbr 4 years ago
committed by David Beal
parent
commit
f153b38c2b
  1. 23
      attachment_synchronize/models/attachment_synchronize_task.py
  2. 2
      attachment_synchronize/tests/test_import.py
  3. 58
      attachment_synchronize/views/attachment_synchronize_task_views.xml

23
attachment_synchronize/models/attachment_synchronize_task.py

@ -54,10 +54,7 @@ class AttachmentSynchronizeTask(models.Model):
[("import", "Import"), ("export", "Export")], required=True
)
pattern = fields.Char(
help="File name which is imported."
"The system will check if the remote file at "
"least contains the pattern in its name. "
"Leave it empty to import all files"
help="Used to select the files to be imported. Import all the files if empty."
)
filepath = fields.Char(
string="File Path", help="Path to imported/exported files in the Backend"
@ -86,26 +83,18 @@ class AttachmentSynchronizeTask(models.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",
help="The file type indicates what Odoo will do with the files once imported",
)
enabled = fields.Boolean("Enabled", default=True)
check_duplicated_files = fields.Boolean(
string="Check duplicated files",
avoid_duplicated_files = fields.Boolean(
string="Avoid duplicated files importation",
help="If checked, will avoid duplication file import",
)
emails = fields.Char(
string="Notification Emails",
help="List of email which should be notified in case of failure "
"when excuting the files linked to this task",
help="These emails will receive a notification in case of the task failure",
)
@api.onchange("method_type")
def onchange_method_type(self):
for task in self:
if task.method_type == "export":
task.file_type = "export"
def _prepare_attachment_vals(self, data, filename):
self.ensure_one()
vals = {
@ -152,7 +141,7 @@ class AttachmentSynchronizeTask(models.Model):
backend = self.backend_id
filepath = self.filepath or ""
filenames = backend._list(relative_path=filepath, pattern=self.pattern)
if self.check_duplicated_files:
if self.avoid_duplicated_files:
filenames = self._file_to_import(filenames)
total_import = 0
for file_name in filenames:

2
attachment_synchronize/tests/test_import.py

@ -63,7 +63,7 @@ class TestImport(SyncCommon):
def test_import_twice_no_duplicate(self):
self.task.write(
{"after_import": "delete", "check_duplicated_files": True}
{"after_import": "delete", "avoid_duplicated_files": True}
)
self.task.run_import()
self._check_attachment_created(count=1)

58
attachment_synchronize/views/attachment_synchronize_task_views.xml

@ -32,33 +32,31 @@
<field name="name" class="oe_inline"/>
</h1>
</div>
<div class="col-12 col-lg-6">
<group class="col-12 col-lg-6">
<field name="method_type"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="pattern" attrs="{'invisible':[('method_type','!=','import')]}"/>
</group>
<group name="action" string="Importation Settings" 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="method_type"/>
<field name="backend_id"/>
<field name="filepath"/>
<field name="pattern" 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')]}"/>
<field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}" />
<field name="emails" attrs="{'invisible':[('method_type','!=','import')]}" />
</group>
<field name="file_type" />
<group string="Data importation settings" attrs="{'invisible':[('method_type','!=','import')]}" >
<field name="check_duplicated_files" />
</group>
</div>
<group string="Attachments" attrs="{'invisible':[('method_type','!=','export')]}">
<field name="attachment_ids" domain="[('task_id', '=', id)]" nolabel="1" />
<field name="attachment_ids" domain="[('task_id', '=', id)]" nolabel="1" attrs="{'invisible':[('method_type','!=','export')]}"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_attachment_task_tree" model="ir.ui.view">
<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">
@ -70,7 +68,21 @@
<field name="backend_id"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" title="Copy" class="fa fa-clone"/>
<button name="button_toogle_enabled" type="object" title="Enable" class="fa fa-archive"/>
<button name="button_toogle_enabled" type="object" title="Enable" class="fa fa-check-square"/>
</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="filepath"/>
<field name="backend_id"/>
<field name="enabled" invisible="1"/>
<button name="button_duplicate_record" type="object" title="Copy" class="fa fa-clone"/>
<button name="button_toogle_enabled" type="object" title="Enable" class="fa fa-check-square"/>
</tree>
</field>
</record>
@ -97,12 +109,13 @@
<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_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="view_id" ref="view_attachment_import_task_tree"/>
<field name="act_window_id" ref="action_attachment_import_task"/>
</record>
@ -128,12 +141,13 @@
<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_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="view_id" ref="view_attachment_export_task_tree"/>
<field name="act_window_id" ref="action_attachment_export_task"/>
</record>

Loading…
Cancel
Save