Skip to content

Commit 96b6480

Browse files
committed
[IMP]website_sale_require_state: Require State
Require state selection on address management on checkout
1 parent 0c9e48e commit 96b6480

File tree

7 files changed

+207
-0
lines changed

7 files changed

+207
-0
lines changed

website_sale_require_state/README.rst

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. |company| replace:: ADHOC SA
2+
3+
.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
4+
:alt: ADHOC SA
5+
:target: https://www.adhoc.com.ar
6+
7+
.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png
8+
9+
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
10+
:target: https://www.gnu.org/licenses/agpl
11+
:alt: License: AGPL-3
12+
13+
==========================
14+
Website Sale Require State
15+
==========================
16+
17+
#. This module prevents from moving forward on the checkout process unless you manually select a state on address management.
18+
19+
Installation
20+
============
21+
22+
To install this module, you need to:
23+
24+
#. Just install this module.
25+
26+
Configuration
27+
=============
28+
29+
To configure this module, you need to:
30+
31+
#. No configuration needed.
32+
33+
Usage
34+
=====
35+
36+
To use this module, you need to:
37+
38+
#. Just use the module.
39+
40+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
41+
:alt: Try me on Runbot
42+
:target: http://runbot.adhoc.com.ar/
43+
44+
Bug Tracker
45+
===========
46+
47+
Bugs are tracked on `GitHub Issues
48+
<https://github.com/ingadhoc/website/issues>`_. In case of trouble, please
49+
check there if your issue has already been reported. If you spotted it first,
50+
help us smashing it by providing a detailed and welcomed feedback.
51+
52+
Credits
53+
=======
54+
55+
Images
56+
------
57+
58+
* |company| |icon|
59+
60+
Contributors
61+
------------
62+
63+
Maintainer
64+
----------
65+
66+
|company_logo|
67+
68+
This module is maintained by the |company|.
69+
70+
To contribute to this module, please visit https://www.adhoc.com.ar.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from . import controllers
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
##############################################################################
2+
#
3+
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
4+
# All Rights Reserved.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Affero General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
##############################################################################
20+
{
21+
'name': 'Website Sale Require State',
22+
'version': '13.0.1.0.0',
23+
'author': 'ADHOC SA',
24+
'website': 'www.adhoc.com.ar',
25+
'license': 'AGPL-3',
26+
'depends': [
27+
'website_sale',
28+
],
29+
'test': [],
30+
'demo': [],
31+
'data': [
32+
'views/website_sale_require_state.xml',
33+
],
34+
'application': False,
35+
'installable': True,
36+
'auto_install': False,
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from . import main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from odoo.addons.website_sale.controllers.main import WebsiteSale
6+
from odoo import http
7+
from odoo.http import request
8+
9+
10+
class WebsiteSaleRequiredState(WebsiteSale):
11+
12+
def _get_mandatory_billing_fields(self):
13+
return ["name", "email", "street", "city", "country_id", "state_id"]
14+
15+
def _get_mandatory_shipping_fields(self):
16+
return ["name", "street", "city", "country_id", "state_id"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
odoo.define('website_sale_require_state.requireState', function (require) {
2+
'use strict';
3+
4+
5+
var publicWidget = require('web.public.widget');
6+
require('website_sale.website_sale');
7+
8+
9+
10+
publicWidget.registry.WebsiteSale.include({
11+
12+
/**
13+
* @override
14+
* @private
15+
*/
16+
_changeCountry: function () {
17+
if (!$("#country_id").val()) {
18+
return;
19+
}
20+
this._rpc({
21+
route: "/shop/country_infos/" + $("#country_id").val(),
22+
params: {
23+
mode: 'shipping',
24+
},
25+
}).then(function (data) {
26+
// placeholder phone_code
27+
//$("input[name='phone']").attr('placeholder', data.phone_code !== 0 ? '+'+ data.phone_code : '');
28+
29+
// populate states and display
30+
var selectStates = $("select[name='state_id']");
31+
// dont reload state at first loading (done in qweb)
32+
if (selectStates.data('init') === 0 || selectStates.find('option').length === 1) {
33+
if (data.states.length) {
34+
selectStates.html('');
35+
selectStates.append('<option value="">Select...</option>');
36+
_.each(data.states, function (x) {
37+
var opt = $('<option>').text(x[1])
38+
.attr('value', x[0])
39+
.attr('data-code', x[2]);
40+
selectStates.append(opt);
41+
});
42+
selectStates.parent('div').show();
43+
} else {
44+
selectStates.val('').parent('div').hide();
45+
}
46+
selectStates.data('init', 0);
47+
} else {
48+
selectStates.data('init', 0);
49+
}
50+
51+
// manage fields order / visibility
52+
if (data.fields) {
53+
if ($.inArray('zip', data.fields) > $.inArray('city', data.fields)) {
54+
$(".div_zip").before($(".div_city"));
55+
} else {
56+
$(".div_zip").after($(".div_city"));
57+
}
58+
var all_fields = ["street", "zip", "city", "country_name"]; // "state_code"];
59+
_.each(all_fields, function (field) {
60+
$(".checkout_autoformat .div_" + field.split('_')[0]).toggle($.inArray(field, data.fields) >= 0);
61+
});
62+
}
63+
});
64+
},
65+
})
66+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<template id="assets_frontend" name="RequireState assets" inherit_id="web.assets_frontend">
4+
<xpath expr="script[last()]" position="after">
5+
<script type="text/javascript" src="/website_sale_require_state/static/src/js/website_sale_require_state.js"></script>
6+
</xpath>
7+
</template>
8+
</odoo>

0 commit comments

Comments
 (0)