Skip to content

Commit

Permalink
Merge pull request OCA#174 from Tecnativa/9.0-website_sale_vat_requir…
Browse files Browse the repository at this point in the history
…ed-mig

[MIG][9.0][website_sale_vat_required] Migrate
  • Loading branch information
pedrobaeza committed Jun 8, 2017
2 parents 04bfe3f + 9e76821 commit 34f57c2
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
56 changes: 56 additions & 0 deletions website_sale_vat_required/README.rst
@@ -0,0 +1,56 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=======================
e-commerce required VAT
=======================

This module extends checkout e-commerce form in order to force user to fill
'VAT number' field.

Usage
=====

To use this module, you need to:

#. Buy something from your e-commerce
#. Go to checkout page.
#. Try to checkout without specifying a VAT, or using a wrong one.
#. You will get an error.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/113/9.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/e-commerce/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
6 changes: 6 additions & 0 deletions website_sale_vat_required/__init__.py
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
25 changes: 25 additions & 0 deletions website_sale_vat_required/__openerp__.py
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'e-commerce required VAT',
'summary': 'VAT number required in checkout form',
'version': '9.0.1.0.0',
'category': 'Website',
'author': "Agile Business Group, "
"Tecnativa, "
"Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
'depends': [
'website_sale',
'base_vat',
],
'demo': [
'demo/assets.xml',
],
'installable': True,
'auto_install': False,
}
6 changes: 6 additions & 0 deletions website_sale_vat_required/controllers/__init__.py
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import main
22 changes: 22 additions & 0 deletions website_sale_vat_required/controllers/main.py
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.addons.website_sale.controllers.main import website_sale


class WebsiteSale(website_sale):
def _get_mandatory_billing_fields(self):
result = super(WebsiteSale, self)._get_mandatory_billing_fields()
result.append("vat")
return result

def _get_optional_billing_fields(self):
result = super(WebsiteSale, self)._get_optional_billing_fields()
try:
result.remove("vat")
except ValueError: # pragma: no-cover
# If any other addon removed it already, do not die
pass
return result
14 changes: 14 additions & 0 deletions website_sale_vat_required/demo/assets.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<template id="assets_frontend_demo" inherit_id="website.assets_frontend">
<xpath expr=".">
<script type="text/javascript"
src="/website_sale_vat_required/static/src/js/website_sale.tour.js"/>
</xpath>
</template>

</odoo>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions website_sale_vat_required/static/src/js/website_sale.tour.js
@@ -0,0 +1,23 @@
/* Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */

odoo.define('website_sale_vat_required.tour', function (require) {
"use strict";

require("website_sale.tour");
var buy_tour = require('web.Tour').tours["shop_buy_product"];

buy_tour.steps.forEach(function (value, index) {
// Search upstream tour step that would fail with this addon installed
if (value.title === "test without input error") {
// Patch step's `onload` method
var oldonload = value.onload;
value.onload = function () {
// Fill VAT field with a good value
$('.has-error > input[name="vat"]').val("BE0477472701")
return oldonload.apply(this, arguments);
};
return false;
}
});
});

0 comments on commit 34f57c2

Please sign in to comment.