diff --git a/website_sale_require_state/README.rst b/website_sale_require_state/README.rst new file mode 100644 index 00000000..cc68d929 --- /dev/null +++ b/website_sale_require_state/README.rst @@ -0,0 +1,71 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +========================== +Website Sale Require State +========================== + +#. This module prevents from moving forward on the checkout process unless you manually select a state on address management. +#. This module prevents from moving forward on the checkout process unless set a zip code on address management. + +Installation +============ + +To install this module, you need to: + +#. Just install this module. + +Configuration +============= + +To configure this module, you need to: + +#. No configuration needed. + +Usage +===== + +To use this module, you need to: + +#. Just use the module. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +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 smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/website_sale_require_state/__init__.py b/website_sale_require_state/__init__.py new file mode 100644 index 00000000..e0396565 --- /dev/null +++ b/website_sale_require_state/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import controllers diff --git a/website_sale_require_state/__manifest__.py b/website_sale_require_state/__manifest__.py new file mode 100644 index 00000000..e7e0e0db --- /dev/null +++ b/website_sale_require_state/__manifest__.py @@ -0,0 +1,37 @@ +############################################################################## +# +# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Website Sale Require State', + 'version': '13.0.1.0.0', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'depends': [ + 'website_sale', + ], + 'test': [], + 'demo': [], + 'data': [ + 'views/website_sale_require_state.xml', + ], + 'application': False, + 'installable': True, + 'auto_install': False, +} diff --git a/website_sale_require_state/controllers/__init__.py b/website_sale_require_state/controllers/__init__.py new file mode 100644 index 00000000..04298136 --- /dev/null +++ b/website_sale_require_state/controllers/__init__.py @@ -0,0 +1,5 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import main diff --git a/website_sale_require_state/controllers/main.py b/website_sale_require_state/controllers/main.py new file mode 100644 index 00000000..29150e6a --- /dev/null +++ b/website_sale_require_state/controllers/main.py @@ -0,0 +1,16 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo.addons.website_sale.controllers.main import WebsiteSale +from odoo import http +from odoo.http import request + + +class WebsiteSaleRequiredState(WebsiteSale): + + def _get_mandatory_billing_fields(self): + return ["name", "email", "street", "city", "country_id", "state_id", "zip"] + + def _get_mandatory_shipping_fields(self): + return ["name", "street", "city", "country_id", "state_id", "zip"] diff --git a/website_sale_require_state/static/src/js/website_sale_require_state.js b/website_sale_require_state/static/src/js/website_sale_require_state.js new file mode 100644 index 00000000..42d169f2 --- /dev/null +++ b/website_sale_require_state/static/src/js/website_sale_require_state.js @@ -0,0 +1,66 @@ +odoo.define('website_sale_require_state.requireState', function (require) { +'use strict'; + + +var publicWidget = require('web.public.widget'); +require('website_sale.website_sale'); + + + +publicWidget.registry.WebsiteSale.include({ + + /** + * @override + * @private + */ + _changeCountry: function () { + if (!$("#country_id").val()) { + return; + } + this._rpc({ + route: "/shop/country_infos/" + $("#country_id").val(), + params: { + mode: 'shipping', + }, + }).then(function (data) { + // placeholder phone_code + //$("input[name='phone']").attr('placeholder', data.phone_code !== 0 ? '+'+ data.phone_code : ''); + + // populate states and display + var selectStates = $("select[name='state_id']"); + // dont reload state at first loading (done in qweb) + if (selectStates.data('init') === 0 || selectStates.find('option').length === 1) { + if (data.states.length) { + selectStates.html(''); + selectStates.append(''); + _.each(data.states, function (x) { + var opt = $('