Skip to content

Commit

Permalink
[14.0][ADD] script_file_import
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Sep 18, 2023
1 parent 6805049 commit 903e7af
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions script_file_import/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions script_file_import/__manifest__.py
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",
],
}
2 changes: 2 additions & 0 deletions script_file_import/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import script_file_import
from . import abstract_script_processor
33 changes: 33 additions & 0 deletions script_file_import/models/abstract_script_processor.py
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
27 changes: 27 additions & 0 deletions script_file_import/models/script_file_import.py
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)
1 change: 1 addition & 0 deletions script_file_import/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Kévin Roche <[email protected]>
1 change: 1 addition & 0 deletions script_file_import/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to
1 change: 1 addition & 0 deletions script_file_import/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to
3 changes: 3 additions & 0 deletions script_file_import/security/ir.model.access.csv
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
21 changes: 21 additions & 0 deletions script_file_import/views/menu.xml
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>
24 changes: 24 additions & 0 deletions script_file_import/views/script_file_import.xml
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>
1 change: 1 addition & 0 deletions setup/script_file_import/odoo/addons/script_file_import
6 changes: 6 additions & 0 deletions setup/script_file_import/setup.py
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,
)

0 comments on commit 903e7af

Please sign in to comment.