Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.0 mig website_sale_vat_required #236

Merged
merged 5 commits into from
Jun 22, 2018
Merged
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
1 change: 1 addition & 0 deletions website_sale_vat_required/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**This file is going to be generated by oca-gen-addon-readme.**
5 changes: 5 additions & 0 deletions website_sale_vat_required/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 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
27 changes: 27 additions & 0 deletions website_sale_vat_required/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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': '11.0.1.0.0',
'category': 'Website',
'author': "Agile Business Group, "
"Tecnativa, "
"Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/e-commerce',
'license': 'AGPL-3',
'depends': [
'website_sale',
'base_vat',
],
'data': [
'views/templates.xml',
],
'demo': [
'demo/demo_assets.xml',
],
'installable': True,
'auto_install': False,
}
5 changes: 5 additions & 0 deletions website_sale_vat_required/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 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
12 changes: 12 additions & 0 deletions website_sale_vat_required/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 odoo.addons.website_sale.controllers.main import WebsiteSale


class WebsiteSale(WebsiteSale):
def _get_mandatory_billing_fields(self):
result = super(WebsiteSale, self)._get_mandatory_billing_fields()
result.append("vat")
return result
13 changes: 13 additions & 0 deletions website_sale_vat_required/demo/demo_assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- License AGPL-3.0 (http://www.gnu.org/licenses/agpl.html). -->

<odoo>

<template id="website_sale_vat_required_assets_frontend_demo" inherit_id="website_sale.assets_frontend">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript"
src="/website_sale_vat_required/static/src/js/website_sale_vat_required.tour.js"/>
</xpath>
</template>

</odoo>
5 changes: 5 additions & 0 deletions website_sale_vat_required/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* `Tecnativa <https://www.tecnativa.com>`_:

* Jairo Llopis
* Ernesto Tejeda
2 changes: 2 additions & 0 deletions website_sale_vat_required/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends checkout e-commerce form in order to force user to fill
'VAT number' field.
6 changes: 6 additions & 0 deletions website_sale_vat_required/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/

odoo.define('website_sale_vat_required.tour', function(require) {

"use strict";

require("website_sale.tour");
var base = require("web_editor.base");
var tour = require("web_tour.tour");
var steps = tour.tours.shop_buy_product.steps;

steps.splice(
_.findIndex(steps, { 'content': "Confirm checkout"}),
0,
{
content: 'Next',
trigger: ".btn-primary:contains('Next')",
},
{
content: 'Set VAT',
trigger: "div.has-error input[name='vat']",
extra_trigger: "div.has-error input[name='vat']",
run: function (actions) {
$('div.has-error input[name="vat"]').val("BE0477472701");
if ($('#div_phone').hasClass('has-error')){
$('#div_phone input').val('11111111');
}
var input_accept_legal_terms = $('div.has-error input[name="accepted_legal_terms"]');
if (!_.isUndefined(input_accept_legal_terms && !input_accept_legal_terms== false)){
$('div.has-error input[name="accepted_legal_terms"]').prop( "checked", true );
}
}
},
{
content: 'Next',
trigger: ".btn-primary:contains('Next')",
}
);
});
16 changes: 16 additions & 0 deletions website_sale_vat_required/views/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="address" inherit_id="website_sale.address" name="Address Management">
<xpath expr="//input[@name='vat']/.." position="replace"/>
<xpath expr="//input[@name='company_name']/../.." position="after">
<t t-if="mode[1] == 'billing'">
<div t-attf-class="form-group #{error.get('vat') and 'has-error' or ''} col-md-6 div_vat">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. It seems included upstream already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration has been made from v9 directly . In v9 the only thing you need to do is set 'vat' as mandatory field using _get_mandatory_billing_fields method. In v10 and v11, if you only do that and you don't modify the template 'address', then, when an user is logged in, odoo will not permit to complete the form until this field is filled, but this field will be hide and the user will wonder what happened. This is, because now, odoo only show this field if there is no user logged in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting. So, Odoo doesn't let a user modify his VAT number. IMHO that makes sense; if you need to change such field, you're probably better creating a new customer.

Then maybe you should only require vat when he's adding a new address. I think you can check that by making sure there's no request.params["partner_id"].

<label class="control-label font-weight-normal" for="vat">TIN / VAT </label>
<input type="text" name="vat" class="form-control" t-att-value="'vat' in checkout and checkout['vat']" />
</div>
</t>
</xpath>
</template>

</odoo>