-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
145 additions
and
0 deletions.
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,33 @@ | ||
# 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 csv | ||
|
||
from odoo import models | ||
|
||
|
||
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 = [] | ||
for line in csv.reader(data): | ||
output.append(self._process_line(line)) | ||
headers |= set(output.keys()) | ||
return self.write_output(headers, output) | ||
|
||
def write_output(self, headers, output): | ||
writer = csv.DictWriter( | ||
output, | ||
delimiter=",", | ||
quotechar='"', | ||
fieldnames=headers, | ||
) | ||
|
||
return data |
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,27 @@ | ||
# 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_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 | ||
) | ||
|
||
def _get_processor(self): | ||
return [] | ||
|
||
def run(self): | ||
selected_processor = dict( | ||
self._fields["processor"]._description_selection(self.env) | ||
).get(self.processor) | ||
self.out_data = self.env[selected_processor].run(self.in_data) |
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">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,24 @@ | ||
<?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" string="Launch Processor" type="object" /> | ||
</header> | ||
<sheet> | ||
<group> | ||
<field name="in_data" /> | ||
<field name="out_data" readonly="1" /> | ||
<field name="processor" /> | ||
</group> | ||
</sheet> | ||
</form> | ||
</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, | ||
) |