diff --git a/website_sale_address_format/README.rst b/website_sale_address_format/README.rst new file mode 100644 index 0000000000..9faecb1ba3 --- /dev/null +++ b/website_sale_address_format/README.rst @@ -0,0 +1,103 @@ +=========================== +Website Sale Address Format +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1d43f035402cfb8a42784b5a5db90d63d8779bac9d12413f81c9b43daa409e73 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/18.0/website_sale_address_format + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-18-0/e-commerce-18-0-website_sale_address_format + :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/e-commerce&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +The eCommerce address presentation (in /shop/address) of vanilla Odoo +does not cover the format of some countries. + +This module adds the capability to change the address field sequence in +the eCommerce address page. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to Contacts > Configuration > Localization > Countries, and open the +country for which the address field sequence should be adjusted in the +eCommerce address page. + +Update 'Layout in eCommerce Address Forms' field with something like the +below (an example for Japan): + +:: + + %(country_name)s + %(zip)s + %(state_code)s + %(city)s + %(street)s + %(street2)s + +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 +------- + +* Quartile + +Contributors +------------ + +- `Quartile `__: + + - Yoshi Tashiro + - Tim Lai + - Aung Ko Ko Lin + +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. + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_address_format/__init__.py b/website_sale_address_format/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/website_sale_address_format/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_sale_address_format/__manifest__.py b/website_sale_address_format/__manifest__.py new file mode 100644 index 0000000000..87c263f857 --- /dev/null +++ b/website_sale_address_format/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2020-2022 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Website Sale Address Format", + "version": "18.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/e-commerce", + "category": "Website/Website", + "license": "AGPL-3", + "depends": ["website_sale"], + "data": ["views/res_country_views.xml"], + "assets": { + "web.assets_frontend": [ + "website_sale_address_format/static/src/js/website_sale_address_format.esm.js", + ], + }, + "installable": True, +} diff --git a/website_sale_address_format/controllers/__init__.py b/website_sale_address_format/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_sale_address_format/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_sale_address_format/controllers/main.py b/website_sale_address_format/controllers/main.py new file mode 100644 index 0000000000..648c94d507 --- /dev/null +++ b/website_sale_address_format/controllers/main.py @@ -0,0 +1,15 @@ +# Copyright 2020 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import http + +from odoo.addons.website_sale.controllers.main import WebsiteSale + + +class WebsiteSale(WebsiteSale): + @http.route() + def shop_country_info(self, country, address_type, **kw): + res = super().shop_country_info(country, address_type, **kw) + if country.online_address_format: + res["fields"] = country.get_online_address_fields() + return res diff --git a/website_sale_address_format/i18n/es.po b/website_sale_address_format/i18n/es.po new file mode 100644 index 0000000000..da596900fd --- /dev/null +++ b/website_sale_address_format/i18n/es.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_address_format +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-20 20:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: website_sale_address_format +#: model_terms:ir.ui.view,arch_db:website_sale_address_format.view_country_form +msgid "Change the way addresses are displayed in eCommerce address forms" +msgstr "" +"Cambiar la forma en que se muestran las direcciones en los formularios de " +"direcciones de comercio electrónico" + +#. module: website_sale_address_format +#: model:ir.model,name:website_sale_address_format.model_res_country +msgid "Country" +msgstr "País" + +#. module: website_sale_address_format +#: model:ir.model.fields,help:website_sale_address_format.field_res_country__online_address_format +msgid "" +"Display format to use for addresses belonging to this country in eCommerce address forms.\n" +"\n" +"You can use python-style string pattern with all the fields of the address (for example, use '%(street)s' to display the field 'street') plus\n" +"%(state_name)s: the name of the state\n" +"%(state_code)s: the code of the state\n" +"%(country_name)s: the name of the country\n" +"%(country_code)s: the code of the country" +msgstr "" +"Formato de visualización que se utilizará para las direcciones " +"pertenecientes a este país en los formularios de dirección de eCommerce.\n" +"\n" +"Puede utilizar el patrón de cadenas estilo python con todos los campos de la " +"dirección (por ejemplo, utilice '%(street)s' para mostrar el campo 'street') " +"más\n" +"%(state_name)s: el nombre del estado\n" +"%(state_code)s: el código del estado\n" +"%(country_name)s: el nombre del país\n" +"%(country_code)s: el código del país" + +#. module: website_sale_address_format +#: model:ir.model.fields,field_description:website_sale_address_format.field_res_country__online_address_format +msgid "Layout in eCommerce Address Forms" +msgstr "Diseño de formularios de direcciones de comercio electrónico" + +#. module: website_sale_address_format +#: model_terms:ir.ui.view,arch_db:website_sale_address_format.view_country_form +msgid "eCommerce address format..." +msgstr "Formato de dirección de eCommerce..." diff --git a/website_sale_address_format/i18n/website_sale_address_format.pot b/website_sale_address_format/i18n/website_sale_address_format.pot new file mode 100644 index 0000000000..a2f82a5332 --- /dev/null +++ b/website_sale_address_format/i18n/website_sale_address_format.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_address_format +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_address_format +#: model_terms:ir.ui.view,arch_db:website_sale_address_format.view_country_form +msgid "Change the way addresses are displayed in eCommerce address forms" +msgstr "" + +#. module: website_sale_address_format +#: model:ir.model,name:website_sale_address_format.model_res_country +msgid "Country" +msgstr "" + +#. module: website_sale_address_format +#: model:ir.model.fields,help:website_sale_address_format.field_res_country__online_address_format +msgid "" +"Display format to use for addresses belonging to this country in eCommerce address forms.\n" +"\n" +"You can use python-style string pattern with all the fields of the address (for example, use '%(street)s' to display the field 'street') plus\n" +"%(state_name)s: the name of the state\n" +"%(state_code)s: the code of the state\n" +"%(country_name)s: the name of the country\n" +"%(country_code)s: the code of the country" +msgstr "" + +#. module: website_sale_address_format +#: model:ir.model.fields,field_description:website_sale_address_format.field_res_country__online_address_format +msgid "Layout in eCommerce Address Forms" +msgstr "" + +#. module: website_sale_address_format +#: model_terms:ir.ui.view,arch_db:website_sale_address_format.view_country_form +msgid "eCommerce address format..." +msgstr "" diff --git a/website_sale_address_format/models/__init__.py b/website_sale_address_format/models/__init__.py new file mode 100644 index 0000000000..11573766f2 --- /dev/null +++ b/website_sale_address_format/models/__init__.py @@ -0,0 +1 @@ +from . import res_country diff --git a/website_sale_address_format/models/res_country.py b/website_sale_address_format/models/res_country.py new file mode 100644 index 0000000000..2f743da3c2 --- /dev/null +++ b/website_sale_address_format/models/res_country.py @@ -0,0 +1,26 @@ +# Copyright 2022-2022 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import re + +from odoo import fields, models + + +class ResCountry(models.Model): + _inherit = "res.country" + + online_address_format = fields.Text( + string="Layout in eCommerce Address Forms", + help="Display format to use for addresses belonging to this country in " + "eCommerce address forms.\n\n" + "You can use python-style string pattern with all the fields of the address " + "(for example, use '%(street)s' to display the field 'street') plus" + "\n%(state_name)s: the name of the state" + "\n%(state_code)s: the code of the state" + "\n%(country_name)s: the name of the country" + "\n%(country_code)s: the code of the country", + ) + + def get_online_address_fields(self): + self.ensure_one() + return re.findall(r"\((.+?)\)", self.online_address_format) diff --git a/website_sale_address_format/pyproject.toml b/website_sale_address_format/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_address_format/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_address_format/readme/CONFIGURE.md b/website_sale_address_format/readme/CONFIGURE.md new file mode 100644 index 0000000000..c0f625af97 --- /dev/null +++ b/website_sale_address_format/readme/CONFIGURE.md @@ -0,0 +1,15 @@ +Go to Contacts \> Configuration \> Localization \> Countries, and open +the country for which the address field sequence should be adjusted in +the eCommerce address page. + +Update 'Layout in eCommerce Address Forms' field with something like the +below (an example for Japan): + +``` +%(country_name)s +%(zip)s +%(state_code)s +%(city)s +%(street)s +%(street2)s +``` diff --git a/website_sale_address_format/readme/CONTRIBUTORS.md b/website_sale_address_format/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..52d0d30649 --- /dev/null +++ b/website_sale_address_format/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Quartile](https://www.quartile.co): + - Yoshi Tashiro + - Tim Lai + - Aung Ko Ko Lin diff --git a/website_sale_address_format/readme/DESCRIPTION.md b/website_sale_address_format/readme/DESCRIPTION.md new file mode 100644 index 0000000000..011bbd041e --- /dev/null +++ b/website_sale_address_format/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +The eCommerce address presentation (in /shop/address) of vanilla Odoo +does not cover the format of some countries. + +This module adds the capability to change the address field sequence in +the eCommerce address page. diff --git a/website_sale_address_format/static/description/icon.png b/website_sale_address_format/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_address_format/static/description/icon.png differ diff --git a/website_sale_address_format/static/description/index.html b/website_sale_address_format/static/description/index.html new file mode 100644 index 0000000000..8b05c338e5 --- /dev/null +++ b/website_sale_address_format/static/description/index.html @@ -0,0 +1,445 @@ + + + + + +Website Sale Address Format + + + +
+

Website Sale Address Format

+ + +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

The eCommerce address presentation (in /shop/address) of vanilla Odoo +does not cover the format of some countries.

+

This module adds the capability to change the address field sequence in +the eCommerce address page.

+

Table of contents

+ +
+

Configuration

+

Go to Contacts > Configuration > Localization > Countries, and open the +country for which the address field sequence should be adjusted in the +eCommerce address page.

+

Update ‘Layout in eCommerce Address Forms’ field with something like the +below (an example for Japan):

+
+%(country_name)s
+%(zip)s
+%(state_code)s
+%(city)s
+%(street)s
+%(street2)s
+
+
+
+

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

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile:
      +
    • Yoshi Tashiro
    • +
    • Tim Lai
    • +
    • Aung Ko Ko Lin
    • +
    +
  • +
+
+
+

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.

+

This module is part of the OCA/e-commerce project on GitHub.

+

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

+
+
+
+ + diff --git a/website_sale_address_format/static/src/js/website_sale_address_format.esm.js b/website_sale_address_format/static/src/js/website_sale_address_format.esm.js new file mode 100644 index 0000000000..8724d98043 --- /dev/null +++ b/website_sale_address_format/static/src/js/website_sale_address_format.esm.js @@ -0,0 +1,104 @@ +/* global Option */ +/** @odoo-module **/ + +import publicWidget from "@web/legacy/js/public/public_widget"; +import {rpc} from "@web/core/network/rpc"; + +publicWidget.registry.websiteSaleAddress = + publicWidget.registry.websiteSaleAddress.extend({ + /** + * @private + */ + async _changeCountry(init = false) { + const countryId = parseInt(this.addressForm.country_id.value); + if (!countryId) { + return; + } + + const data = await rpc(`/shop/country_info/${parseInt(countryId)}`, { + address_type: this.addressType, + }); + + if (data.phone_code !== 0) { + this.addressForm.phone.placeholder = "+" + data.phone_code; + } else { + this.addressForm.phone.placeholder = ""; + } + + // Populate states and display + var selectStates = this.addressForm.state_id; + if (!init || selectStates.options.length === 1) { + // Dont reload state at first loading (done in qweb) + if (data.states.length || data.state_required) { + // Empty existing options, only keep the placeholder. + selectStates.options.length = 1; + + // Create new options and append them to the select element + data.states.forEach((state) => { + const option = new Option(state[1], state[0]); + // Used by localizations + option.setAttribute("data-code", state[2]); + selectStates.appendChild(option); + }); + this._showInput("state_id"); + } else { + this._hideInput("state_id"); + } + } + + // Manage fields order / visibility + if (data.fields) { + // [CUSTOM][DEL] Following 5 lines + // if (data.zip_before_city) { + // this._getInputDiv('zip').after(this._getInputDiv('city')); + // } else { + // this._getInputDiv('zip').before(this._getInputDiv('city')); + // } + // [CUSTOM][ADD] Following 11 lines: sort fields according to + // online_address_format of the country + let prev = this._getInputDiv("street"); + for (const fname of data.fields) { + let key = fname.split("_")[0]; + if (key === "state") key = "state_id"; + if (key === "country") key = "country_id"; + const el = this._getInputDiv(key); + if (el) { + prev.after(el); + prev = el; + } + } + // [CUSTOM][DEL] Following line + // var all_fields = ['street', 'zip', 'city']; + // [CUSTOM][ADD] street2 and state_code + var all_fields = ["street", "street2", "zip", "city", "state_code"]; + // [EDIT] Following 13 lines + const toInputName = (fname) => { + const key = fname.split("_")[0]; + if (key === "state") return "state_id"; + return key; + }; + all_fields.forEach((fname) => { + const input = toInputName(fname); + if (data.fields.includes(fname)) { + this._showInput(input); + } else { + this._hideInput(input); + } + }); + } + + const required_fields = this.addressForm.querySelectorAll(":required"); + required_fields.forEach((element) => { + // Remove requirement on previously required fields + if ( + !data.required_fields.includes(element.name) && + !this.requiredFields.includes(element.name) + ) { + this._markRequired(element.name, false); + } + }); + data.required_fields.forEach((fieldName) => { + this._markRequired(fieldName, true); + }); + }, + }); diff --git a/website_sale_address_format/tests/__init__.py b/website_sale_address_format/tests/__init__.py new file mode 100644 index 0000000000..c365621335 --- /dev/null +++ b/website_sale_address_format/tests/__init__.py @@ -0,0 +1 @@ +from . import test_website_sale_address_format diff --git a/website_sale_address_format/tests/test_website_sale_address_format.py b/website_sale_address_format/tests/test_website_sale_address_format.py new file mode 100644 index 0000000000..434b9f64d0 --- /dev/null +++ b/website_sale_address_format/tests/test_website_sale_address_format.py @@ -0,0 +1,40 @@ +# Copyright 2020-2022 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install") +class TestWebsiteSaleAddressFormat(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.japan = cls.env.ref("base.jp") + + def test_00_country_infos(self): + self.japan.online_address_format = """ + %(zip)s + %(state_name)s %(city)s + %(street)s + %(street2)s + """ + vals1 = self.japan.get_online_address_fields() + vals1_sorted = ["zip", "state_name", "city", "street", "street2"] + self.assertEqual(vals1, vals1_sorted) + self.japan.online_address_format = """ + %(state_name)s %(city)s + %(zip)s + %(street)s + %(street2)s + %(country_code)s + """ + vals2 = self.japan.get_online_address_fields() + vals2_sorted = [ + "state_name", + "city", + "zip", + "street", + "street2", + "country_code", + ] + self.assertEqual(vals2, vals2_sorted) diff --git a/website_sale_address_format/views/res_country_views.xml b/website_sale_address_format/views/res_country_views.xml new file mode 100644 index 0000000000..1ff318f547 --- /dev/null +++ b/website_sale_address_format/views/res_country_views.xml @@ -0,0 +1,23 @@ + + + + res.country.form + res.country + + + + + + +