Skip to content

Commit 6d13a84

Browse files
committed
[ADD] excel_import_export_unidecode: add module that implements the ability to apply unidecode to each selected data.
1 parent 5b1cced commit 6d13a84

20 files changed

+658
-0
lines changed
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
=====================================
2+
Excel Import/Export/Report: Unidecode
3+
=====================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:19cee33fc5782509b54e57e83d3cf30711505b3c47cb9d34801082b213a3f6d2
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-tools/tree/16.0/excel_import_export_unidecode
21+
:alt: OCA/server-tools
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-excel_import_export_unidecode
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module adds the extra unidecode option to be applied to the exported data. Example: e.g. ESPAÑA to ESPANA or forçut to forcut.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Installation
39+
============
40+
41+
To install this module, you need to install following python library, **unidecode**.
42+
43+
Usage
44+
=====
45+
46+
To apply unidecode just check the Unidecode field for the data where you want to apply it in the Excel template.
47+
If you are defining the template you only have to specify @?unidecode? e.g. 'A2': 'picking_id.export_reference${value or ""}@?unidecode?'
48+
49+
Bug Tracker
50+
===========
51+
52+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
53+
In case of trouble, please check there if your issue has already been reported.
54+
If you spotted it first, help us to smash it by providing a detailed and welcomed
55+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20excel_import_export_unidecode%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
56+
57+
Do not contact contributors directly about support or help with technical issues.
58+
59+
Credits
60+
=======
61+
62+
Authors
63+
~~~~~~~
64+
65+
* FactorLibre
66+
67+
Contributors
68+
~~~~~~~~~~~~
69+
70+
* Rodrigo Bonilla. <[email protected]> (https://factorlibre.com/)
71+
72+
Maintainers
73+
~~~~~~~~~~~
74+
75+
This module is maintained by the OCA.
76+
77+
.. image:: https://odoo-community.org/logo.png
78+
:alt: Odoo Community Association
79+
:target: https://odoo-community.org
80+
81+
OCA, or the Odoo Community Association, is a nonprofit organization whose
82+
mission is to support the collaborative development of Odoo features and
83+
promote its widespread use.
84+
85+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/excel_import_export_unidecode>`_ project on GitHub.
86+
87+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2023 FactorLibre., Ltd (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2023 FactorLibre., Ltd (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
4+
{
5+
"name": "Excel Import/Export/Report: Unidecode",
6+
"summary": "Add unidecode option to excel import/export/report",
7+
"version": "16.0.1.0.0",
8+
"author": "FactorLibre,Odoo Community Association (OCA)",
9+
"license": "AGPL-3",
10+
"website": "https://github.com/OCA/server-tools",
11+
"category": "Tools",
12+
"depends": ["excel_import_export"],
13+
"external_dependencies": {"python": ["unidecode"]},
14+
"data": ["views/xlsx_template_view.xml"],
15+
"installable": True,
16+
"development_status": "Beta",
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2023 FactorLibre (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
from . import common
4+
from . import xlsx_export
5+
from . import xlsx_template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2023 FactorLibre (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
4+
5+
def get_field_unidecode(field):
6+
"""i..e, 'field@?unidecode?'"""
7+
if field and "@?" in field and "?" in field:
8+
i = field.index("@?")
9+
j = field.index("?", i)
10+
cond = field[i + 2 : j]
11+
try:
12+
if cond or cond == "":
13+
return (field[:i], True)
14+
except Exception:
15+
return (field.replace("@?%s?" % cond, ""), False)
16+
return (field, False)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 FactorLibre (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
4+
import unidecode
5+
6+
from odoo import models
7+
8+
from . import common as co
9+
10+
11+
class XLSXExport(models.AbstractModel):
12+
_inherit = "xlsx.export"
13+
14+
def _get_conditions_dict(self):
15+
res = super()._get_conditions_dict()
16+
res.setdefault("field_unidecode_dict", {})
17+
return res
18+
19+
def run_field_unidecode_dict(self, field):
20+
return co.get_field_unidecode(field)
21+
22+
def apply_extra_conditions_to_value(self, field, value, conditions_dict):
23+
res = super().apply_extra_conditions_to_value(field, value, conditions_dict)
24+
if conditions_dict["field_unidecode_dict"][field[0]] and (
25+
isinstance(res, bytes) or isinstance(res, str)
26+
):
27+
if isinstance(res, bytes):
28+
res = res.decode("utf-8")
29+
res = unidecode.unidecode(res)
30+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2023 FactorLibre (https://factorlibre.com/)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
3+
4+
5+
from odoo import api, fields, models
6+
7+
from . import common as co
8+
9+
10+
class XLSXTemplate(models.Model):
11+
_inherit = "xlsx.template"
12+
13+
def _compose_field_name(self, line):
14+
res = super()._compose_field_name(line)
15+
if line.is_unidecode:
16+
res += "@?unidecode?"
17+
return res
18+
19+
20+
class XLSXTemplateExport(models.Model):
21+
_inherit = "xlsx.template.export"
22+
23+
is_unidecode = fields.Boolean(string="Unidecode", default=False)
24+
25+
@api.model
26+
def _extract_field_name(self, vals):
27+
res = super()._extract_field_name(vals)
28+
if self._context.get("compute_from_input") and res.get("field_name"):
29+
field_name, func_unidecode = co.get_field_unidecode(res.get("field_name"))
30+
res.update(
31+
{
32+
"field_name": field_name,
33+
"is_unidecode": func_unidecode,
34+
}
35+
)
36+
37+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Rodrigo Bonilla. <[email protected]> (https://factorlibre.com/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module adds the extra unidecode option to be applied to the exported data. Example: e.g. ESPAÑA to ESPANA or forçut to forcut.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To install this module, you need to install following python library, **unidecode**.

excel_import_export_unidecode/readme/ROADMAP.rst

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
To apply unidecode just check the Unidecode field for the data where you want to apply it in the Excel template.
2+
If you are defining the template you only have to specify @?unidecode? e.g. 'A2': 'picking_id.export_reference${value or ""}@?unidecode?'
Loading
Loading

0 commit comments

Comments
 (0)