Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions website_sale_require_state/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/ingadhoc/website/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.
5 changes: 5 additions & 0 deletions website_sale_require_state/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import controllers
37 changes: 37 additions & 0 deletions website_sale_require_state/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
5 changes: 5 additions & 0 deletions website_sale_require_state/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import main
16 changes: 16 additions & 0 deletions website_sale_require_state/controllers/main.py
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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('<option value="">State / Province...</option>');
_.each(data.states, function (x) {
var opt = $('<option>').text(x[1])
.attr('value', x[0])
.attr('data-code', x[2]);
selectStates.append(opt);
});
selectStates.parent('div').show();
} else {
selectStates.val('').parent('div').hide();
}
selectStates.data('init', 0);
} else {
selectStates.data('init', 0);
}

// manage fields order / visibility
if (data.fields) {
if ($.inArray('zip', data.fields) > $.inArray('city', data.fields)) {
$(".div_zip").before($(".div_city"));
} else {
$(".div_zip").after($(".div_city"));
}
var all_fields = ["street", "zip", "city", "country_name"]; // "state_code"];
_.each(all_fields, function (field) {
$(".checkout_autoformat .div_" + field.split('_')[0]).toggle($.inArray(field, data.fields) >= 0);
});
}
});
},
})
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" name="RequireState assets" inherit_id="web.assets_frontend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/website_sale_require_state/static/src/js/website_sale_require_state.js"></script>
</xpath>
</template>
</odoo>