diff --git a/base_import_strip/README.rst b/base_import_strip/README.rst new file mode 100644 index 000000000..0f0b882e6 --- /dev/null +++ b/base_import_strip/README.rst @@ -0,0 +1,95 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=================== +Base Import - Strip +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7b7615161bb5ade8db8e191e77c5956985c469e5129485193892a557bb86b5ab + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github + :target: https://github.com/OCA/server-backend/tree/16.0/base_import_strip + :alt: OCA/server-backend +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_strip + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the ``base_import`` odoo module. + +by default, in odoo, if a spreadsheet contains the value ' France ' in +a column 'country_id' the according item (``base.fr``) will not be found +because Odoo realize a strict search. +This module 'strip' all the values before importing, and so fixes such +cases. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* `GRAP `_: + * Sylvain LE GAL + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/server-backend `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_import_strip/__init__.py b/base_import_strip/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/base_import_strip/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_import_strip/__manifest__.py b/base_import_strip/__manifest__.py new file mode 100644 index 000000000..711c66317 --- /dev/null +++ b/base_import_strip/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2026 - GRAP - Sylvain LE GAL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Base Import - Strip", + "summary": "Remove whitespaces at the beginning and end of values" + " when importing data from sheets .(csv, ods, ...)", + "version": "16.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/server-backend", + "author": "GRAP, Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "license": "AGPL-3", + "depends": ["base_import"], +} diff --git a/base_import_strip/i18n/fr.po b/base_import_strip/i18n/fr.po new file mode 100644 index 000000000..6af301727 --- /dev/null +++ b/base_import_strip/i18n/fr.po @@ -0,0 +1,6 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_import_strip +# +msgid "" +msgstr "" diff --git a/base_import_strip/models/__init__.py b/base_import_strip/models/__init__.py new file mode 100644 index 000000000..0089b00eb --- /dev/null +++ b/base_import_strip/models/__init__.py @@ -0,0 +1 @@ +from . import base_import_import diff --git a/base_import_strip/models/base_import_import.py b/base_import_strip/models/base_import_import.py new file mode 100644 index 000000000..167ed43f1 --- /dev/null +++ b/base_import_strip/models/base_import_import.py @@ -0,0 +1,13 @@ +# Copyright 2026 - GRAP - Sylvain LE GAL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class BaseImportImport(models.TransientModel): + _inherit = "base_import.import" + + def _read_file(self, options): + nb_rows, rows = super()._read_file(options) + if not self.env.context.get("base_import_strip_disabled"): + rows = [[x.strip() for x in row] for row in rows] + return nb_rows, rows diff --git a/base_import_strip/readme/CONTRIBUTORS.rst b/base_import_strip/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5614cf40f --- /dev/null +++ b/base_import_strip/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* `GRAP `_: + * Sylvain LE GAL \ No newline at end of file diff --git a/base_import_strip/readme/DESCRIPTION.rst b/base_import_strip/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c7b60d235 --- /dev/null +++ b/base_import_strip/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module extends the ``base_import`` odoo module. + +by default, in odoo, if a spreadsheet contains the value ' France ' in +a column 'country_id' the according item (``base.fr``) will not be found +because Odoo realize a strict search. +This module 'strip' all the values before importing, and so fixes such +cases. \ No newline at end of file diff --git a/base_import_strip/static/description/index.html b/base_import_strip/static/description/index.html new file mode 100644 index 000000000..6d468c436 --- /dev/null +++ b/base_import_strip/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Base Import - Strip

+ +

Beta License: AGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

+

This module extends the base_import odoo module.

+

by default, in odoo, if a spreadsheet contains the value ‘ France ‘ in +a column ‘country_id’ the according item (base.fr) will not be found +because Odoo realize a strict search. +This module ‘strip’ all the values before importing, and so fixes such +cases.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

Contributors

+
    +
  • GRAP: +* Sylvain LE GAL
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/server-backend project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/base_import_strip/tests/__init__.py b/base_import_strip/tests/__init__.py new file mode 100644 index 000000000..a002e4f53 --- /dev/null +++ b/base_import_strip/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_import_strip diff --git a/base_import_strip/tests/import_data/res_partner_test.csv b/base_import_strip/tests/import_data/res_partner_test.csv new file mode 100644 index 000000000..ad714fc16 --- /dev/null +++ b/base_import_strip/tests/import_data/res_partner_test.csv @@ -0,0 +1 @@ + Partner Name , France , diff --git a/base_import_strip/tests/test_base_import_strip.py b/base_import_strip/tests/test_base_import_strip.py new file mode 100644 index 000000000..4ff3dcfe4 --- /dev/null +++ b/base_import_strip/tests/test_base_import_strip.py @@ -0,0 +1,39 @@ +# Copyright 2026 - GRAP - Sylvain LE GAL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from os import path + +from odoo.tests.common import TransactionCase + +PATH = path.join(path.dirname(__file__), "import_data", "%s.csv") +FIELDS = ["name", "country_id", "vat"] +OPTIONS = {"headers": True, "quoting": "'", "separator": ","} + + +class ImportCase(TransactionCase): + def _import_file(self, disabled=False): + _file = open(PATH % "res_partner_test") + record = ( + self.env["base_import.import"] + .with_context(base_import_strip_disabled=disabled) + .create( + { + "res_model": "res.partner", + "file": _file.read(), + "file_name": "%res_partner_test.csv", + "file_type": "csv", + } + ) + ) + record.execute_import(FIELDS, [], OPTIONS) + + def test_disabled(self): + self._import_file(disabled=True) + last_partner = self.env["res.partner"].search([], order="id desc", limit=1) + self.assertNotEqual(last_partner.name, "Partner Name") + + def test_enabled(self): + self._import_file(disabled=False) + last_partner = self.env["res.partner"].search([], order="id desc", limit=1) + self.assertEqual(last_partner.name, "Partner Name") + self.assertEqual(last_partner.country_id, self.env.ref("base.fr")) diff --git a/setup/base_import_strip/odoo/addons/base_import_strip b/setup/base_import_strip/odoo/addons/base_import_strip new file mode 120000 index 000000000..1463bd07c --- /dev/null +++ b/setup/base_import_strip/odoo/addons/base_import_strip @@ -0,0 +1 @@ +../../../../base_import_strip \ No newline at end of file diff --git a/setup/base_import_strip/setup.py b/setup/base_import_strip/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/base_import_strip/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)