[IMP] rename check_duplicated_files and improve Task views
parent
81462638a6
commit
cacacc99fb
|
@ -54,10 +54,7 @@ class AttachmentSynchronizeTask(models.Model):
|
||||||
[("import", "Import"), ("export", "Export")], required=True
|
[("import", "Import"), ("export", "Export")], required=True
|
||||||
)
|
)
|
||||||
pattern = fields.Char(
|
pattern = fields.Char(
|
||||||
help="File name which is imported."
|
help="Used to select the files to be imported. Import all the files if empty."
|
||||||
"The system will check if the remote file at "
|
|
||||||
"least contains the pattern in its name. "
|
|
||||||
"Leave it empty to import all files"
|
|
||||||
)
|
)
|
||||||
filepath = fields.Char(
|
filepath = fields.Char(
|
||||||
string="File Path", help="Path to imported/exported files in the Backend"
|
string="File Path", help="Path to imported/exported files in the Backend"
|
||||||
|
@ -86,26 +83,18 @@ class AttachmentSynchronizeTask(models.Model):
|
||||||
file_type = fields.Selection(
|
file_type = fields.Selection(
|
||||||
selection=[],
|
selection=[],
|
||||||
string="File Type",
|
string="File Type",
|
||||||
help="The file type determines an import method to be used "
|
help="The file type indicates what Odoo will do with the files once imported",
|
||||||
"to parse and transform data before their import in ERP",
|
|
||||||
)
|
)
|
||||||
enabled = fields.Boolean("Enabled", default=True)
|
enabled = fields.Boolean("Enabled", default=True)
|
||||||
check_duplicated_files = fields.Boolean(
|
avoid_duplicated_files = fields.Boolean(
|
||||||
string="Check duplicated files",
|
string="Avoid duplicated files importation",
|
||||||
help="If checked, will avoid duplication file import",
|
help="If checked, will avoid duplication file import",
|
||||||
)
|
)
|
||||||
emails = fields.Char(
|
emails = fields.Char(
|
||||||
string="Notification Emails",
|
string="Notification Emails",
|
||||||
help="List of email which should be notified in case of failure "
|
help="These emails will receive a notification in case of the task failure",
|
||||||
"when excuting the files linked to this task",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@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):
|
def _prepare_attachment_vals(self, data, filename):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
vals = {
|
vals = {
|
||||||
|
@ -152,7 +141,7 @@ class AttachmentSynchronizeTask(models.Model):
|
||||||
backend = self.backend_id
|
backend = self.backend_id
|
||||||
filepath = self.filepath or ""
|
filepath = self.filepath or ""
|
||||||
filenames = backend._list(relative_path=filepath, pattern=self.pattern)
|
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)
|
filenames = self._file_to_import(filenames)
|
||||||
total_import = 0
|
total_import = 0
|
||||||
for file_name in filenames:
|
for file_name in filenames:
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestImport(SyncCommon):
|
||||||
|
|
||||||
def test_import_twice_no_duplicate(self):
|
def test_import_twice_no_duplicate(self):
|
||||||
self.task.write(
|
self.task.write(
|
||||||
{"after_import": "delete", "check_duplicated_files": True}
|
{"after_import": "delete", "avoid_duplicated_files": True}
|
||||||
)
|
)
|
||||||
self.task.run_import()
|
self.task.run_import()
|
||||||
self._check_attachment_created(count=1)
|
self._check_attachment_created(count=1)
|
||||||
|
|
|
@ -32,33 +32,31 @@
|
||||||
<field name="name" class="oe_inline"/>
|
<field name="name" class="oe_inline"/>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</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>
|
<group>
|
||||||
<field name="method_type"/>
|
<field name="file_type" attrs="{'invisible':[('method_type','!=','import')]}" />
|
||||||
<field name="backend_id"/>
|
<field name="emails" attrs="{'invisible':[('method_type','!=','import')]}" />
|
||||||
<field name="filepath"/>
|
|
||||||
<field name="pattern" attrs="{'invisible':[('method_type','!=','import')]}"/>
|
|
||||||
</group>
|
</group>
|
||||||
<group name="action" string="Action">
|
<field name="attachment_ids" domain="[('task_id', '=', id)]" nolabel="1" attrs="{'invisible':[('method_type','!=','export')]}"/>
|
||||||
<field name="emails"/>
|
|
||||||
<field name="after_import" attrs="{'invisible':[('method_type','!=','import')]}"/>
|
|
||||||
<field name="move_path" colspan="4" attrs="{'invisible':['|', '&', ('after_import','!=','move'), ('after_import','!=','move_rename'), ('method_type','!=','import')]}"/>
|
|
||||||
<field name="new_name" colspan="4" attrs="{'invisible': ['|', '&', ('after_import','!=','rename'), ('after_import','!=','move_rename'), ('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" />
|
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</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="model">attachment.synchronize.task</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Tasks" decoration-muted="enabled == False">
|
<tree string="Tasks" decoration-muted="enabled == False">
|
||||||
|
@ -70,7 +68,21 @@
|
||||||
<field name="backend_id"/>
|
<field name="backend_id"/>
|
||||||
<field name="enabled" invisible="1"/>
|
<field name="enabled" invisible="1"/>
|
||||||
<button name="button_duplicate_record" type="object" title="Copy" class="fa fa-clone"/>
|
<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>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -97,12 +109,13 @@
|
||||||
<field name="view_id" eval="False"/>
|
<field name="view_id" eval="False"/>
|
||||||
<field name="search_view_id" ref="view_attachment_task_search"/>
|
<field name="search_view_id" ref="view_attachment_task_search"/>
|
||||||
<field name="domain">[('method_type', '=', 'import')]</field>
|
<field name="domain">[('method_type', '=', 'import')]</field>
|
||||||
|
<field name="context">{'default_method_type': 'import'}</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="act_open_attachment_task_view_tree" model="ir.actions.act_window.view">
|
<record id="act_open_attachment_task_view_tree" model="ir.actions.act_window.view">
|
||||||
<field eval="10" name="sequence"/>
|
<field eval="10" name="sequence"/>
|
||||||
<field name="view_mode">tree</field>
|
<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"/>
|
<field name="act_window_id" ref="action_attachment_import_task"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
@ -128,12 +141,13 @@
|
||||||
<field name="view_id" eval="False"/>
|
<field name="view_id" eval="False"/>
|
||||||
<field name="search_view_id" ref="view_attachment_task_search"/>
|
<field name="search_view_id" ref="view_attachment_task_search"/>
|
||||||
<field name="domain">[('method_type', '=', 'export')]</field>
|
<field name="domain">[('method_type', '=', 'export')]</field>
|
||||||
|
<field name="context">{'default_method_type': 'export'}</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="act_open_attachment_task_view_tree" model="ir.actions.act_window.view">
|
<record id="act_open_attachment_task_view_tree" model="ir.actions.act_window.view">
|
||||||
<field eval="10" name="sequence"/>
|
<field eval="10" name="sequence"/>
|
||||||
<field name="view_mode">tree</field>
|
<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"/>
|
<field name="act_window_id" ref="action_attachment_export_task"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue