-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][ADD] script_file_import #279
Open
Kev-Roche
wants to merge
3
commits into
14.0
Choose a base branch
from
add_script_file_import
base: 14.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Kévin Roche <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Script File Import", | ||
"summary": "base module for import with script", | ||
"version": "14.0.1.0.0", | ||
"category": "tools", | ||
"website": "https://github.com/akretion/ak-odoo-incubator", | ||
"author": "Akretion, Odoo Community Association (OCA)", | ||
"maintainers": ["Kev-Roche"], | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"pattern_import_export", | ||
], | ||
"data": [ | ||
"views/menu.xml", | ||
"views/script_file_import.xml", | ||
"security/ir.model.access.csv", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import script_file_import | ||
from . import abstract_script_processor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Kévin Roche <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import base64 | ||
import csv | ||
import io | ||
import logging | ||
|
||
from odoo import models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class AbstractScriptProcessor(models.AbstractModel): | ||
_name = "abstract.script.processor" | ||
_description = "Abstract Script Processor" | ||
|
||
def _process_line(self, line): | ||
raise NotImplementedError() | ||
|
||
def run(self, data): | ||
headers = set() | ||
output = [] | ||
in_file = io.StringIO(base64.b64decode(data).decode("utf-8")) | ||
reader = csv.DictReader(in_file) | ||
for idx, line in enumerate(reader): | ||
_logger.info("Process line %s", idx) | ||
self.flush() | ||
try: | ||
with self.env.cr.savepoint(): | ||
self._process_line(line) | ||
except Exception as e: | ||
line["error"] = str(e) | ||
output.append(line) | ||
_logger.error("Script import error %s", e) | ||
headers = ["error"] + reader.fieldnames | ||
return self.write_output(headers, output, reader.dialect) | ||
|
||
def write_output(self, headers, data, dialect): | ||
f = io.StringIO() | ||
writer = csv.DictWriter( | ||
f, | ||
dialect=dialect, | ||
fieldnames=headers, | ||
) | ||
writer.writeheader() | ||
for row in data: | ||
writer.writerow(row) | ||
f.seek(0) | ||
return base64.b64encode(f.read().encode("utf-8")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2023 Akretion (https://www.akretion.com). | ||
# @author Kévin Roche <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ScriptFileImport(models.Model): | ||
_name = "script.file.import" | ||
_description = "Script File Import" | ||
|
||
in_filename = fields.Char() | ||
out_filename = fields.Char(compute="_compute_out_filename") | ||
|
||
in_data = fields.Binary(string="Input CSV file", required=True) | ||
|
||
out_data = fields.Binary(string="Output CSV file", readonly=True) | ||
|
||
processor = fields.Selection( | ||
string="Processor", selection="_get_processor", required=True | ||
) | ||
state = fields.Selection( | ||
[ | ||
("draft", "Draft"), | ||
("processing", "Processing"), | ||
("done", "Done"), | ||
], | ||
) | ||
|
||
def _get_processor(self): | ||
return [] | ||
|
||
def run_in_background(self): | ||
self.state = "processing" | ||
self.with_delay().run() | ||
|
||
def run(self): | ||
self.out_data = self.env[self.processor].run(self.in_data) | ||
self.state = "done" | ||
|
||
def _compute_out_filename(self): | ||
for record in self: | ||
record.out_filename = "Result-" + record.in_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Kévin Roche <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_script_file_import,script.file.import.user,model_script_file_import,base.group_user,1,1,1,1 | ||
access_abstract_script_processor,abstract.script.processor.user,model_abstract_script_processor,base.group_user,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright (C) 2023 Akretion (<http://www.akretion.com>). | ||
@author Kévin Roche <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="action_script_file_import" model="ir.actions.act_window"> | ||
<field name="name">Script File Import</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">script.file.import</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
|
||
<menuitem | ||
id="script_file_import_menu" | ||
name="Script File Import" | ||
parent="pattern_import_export.import_export_menu_root" | ||
sequence="10" | ||
groups="base.group_user" | ||
action="action_script_file_import" | ||
/> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright (C) 2023 Akretion (<http://www.akretion.com>). | ||
@author Kévin Roche <[email protected]> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="script_file_import_view_form" model="ir.ui.view"> | ||
<field name="name">script_file_import_form</field> | ||
<field name="model">script.file.import</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<header> | ||
<button | ||
name="run_in_background" | ||
string="Launch Processor" | ||
type="object" | ||
/> | ||
<field | ||
name="state" | ||
widget="statusbar" | ||
statusbar_visible="draft,processing,done" | ||
/> | ||
</header> | ||
<sheet> | ||
<group> | ||
<field name="in_filename" invisible="1" /> | ||
<field name="out_filename" invisible="1" /> | ||
<field name="in_data" filename="in_filename" /> | ||
<field | ||
name="out_data" | ||
filename="out_filename" | ||
readonly="1" | ||
/> | ||
<field name="processor" /> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="script_file_import_view_tree" model="ir.ui.view"> | ||
<field name="model">script.file.import</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Script"> | ||
<field name="in_filename" /> | ||
<field name="create_date" /> | ||
<field name="state" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="script_file_import_view_search" model="ir.ui.view"> | ||
<field name="model">script.file.import</field> | ||
<field name="arch" type="xml"> | ||
<search string="Script"> | ||
<field name="in_filename" /> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../script_file_import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous line ?