Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pattern_import_export/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
* Sébastien Beau <sebastien.beau@akretion.com>
* François Honoré (ACSONE SA/NV) <francois.honore@acsone.eu>
* Kevin Khao <kevin.khao@akretion.com>
* Tony Gu <tony@openerp.cn>
19 changes: 18 additions & 1 deletion pattern_import_export/wizard/import_pattern_wizard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import fields, models, api


class ImportPatternWizard(models.TransientModel):
Expand All @@ -14,6 +14,15 @@ class ImportPatternWizard(models.TransientModel):
_name = "import.pattern.wizard"
_description = "Import pattern wizard"

def _get_model(self):
model_name = self.env.context.get('active_model')
active_id = self.env.context.get('active_id')
if model_name == "pattern.config":
pattern_config = self.env[model_name].browse(active_id)
model_name = pattern_config.resource
return model_name


pattern_config_id = fields.Many2one(
comodel_name="pattern.config",
string="Import pattern",
Expand All @@ -23,7 +32,15 @@ class ImportPatternWizard(models.TransientModel):
)
import_file = fields.Binary(string="File to import", required=True)
filename = fields.Char()
model = fields.Char(default=_get_model)
no_import_pattern = fields.Boolean(compute="_compute_no_import_pattern")

@api.depends("model")
def _compute_no_import_pattern(self):
for wiz in self:
wiz.no_import_pattern = not wiz.env["pattern.config"].search_count(
[("resource", "=", wiz.model)]
)
def action_launch_import(self):
"""

Expand Down
33 changes: 23 additions & 10 deletions pattern_import_export/wizard/import_pattern_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,32 @@
<form>
<group>
<group>
<field name="model" invisible="1" />
<field name="no_import_pattern" invisible="1" />
<field
name="pattern_config_id"
options="{'no_create_edit': True}"
invisible="context.get('hide_pattern_config_id')"
/>
<field name="filename" invisible="1" />
<field
name="import_file"
filename="filename"
placeholder="Choose a file to import..."
domain="[('resource', '=', model)]"
options="{'no_create': True, 'no_edit': True}"
attrs="{'invisible': [('no_import_pattern', '=', True)]}"

/>
<span
attrs="{'invisible': [('no_import_pattern', '=', False)]}"
colspan="2"
>
There is no import pattern for this object !<br />
Please go to the menu .... and create one.
</span>
<field name="filename" invisible="1" />
<field
name="import_file"
filename="filename"
placeholder="Choose a file to import..."
attrs="{'invisible': [('no_import_pattern', '=', True)]}"
/>
</group>
<group colspan="2">
</group>
<group colspan="2"
attrs="{'invisible': [('no_import_pattern', '=', True)]}" >
<div class="oe_form_box_danger oe_text_center">
<p>
<strong
Expand Down