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_require_legal #237

Merged
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 oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
website
1 change: 1 addition & 0 deletions website_sale_require_legal/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.**
4 changes: 4 additions & 0 deletions website_sale_require_legal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2015 Tecnativa - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import controllers
26 changes: 26 additions & 0 deletions website_sale_require_legal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2015, 2017 Tecnativa - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Require accepting legal terms to checkout",
"summary": "Force the user to accept legal tems to buy in the web shop",
"version": "11.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"web_tour",
"website_legal_page",
"website_sale",
],
"data": [
"views/website_sale.xml",
],
"demo": [
"demo/assets.xml",
],
}
2 changes: 2 additions & 0 deletions website_sale_require_legal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import main
56 changes: 56 additions & 0 deletions website_sale_require_legal/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2015-2017 Tecnativa - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import SUPERUSER_ID
from odoo.http import request
from odoo.addons.website_sale.controllers import main


class WebsiteSale(main.WebsiteSale):
def _get_mandatory_billing_fields(self):
result = super(WebsiteSale, self)._get_mandatory_billing_fields()
return result + self._mandatory_legal_terms()

def _get_mandatory_shipping_fields(self):
result = super(WebsiteSale, self)._get_mandatory_shipping_fields()
return result + self._mandatory_legal_terms()

def _mandatory_legal_terms(self):
"""Require ``accepted_legal_terms`` only if we are validating."""
result = []
if request.context.get("needs_legal"):
result.append("accepted_legal_terms")
return result

def checkout_form_validate(self, mode, all_form_values, data):
"""Require accepting legal terms to validate form."""
# Patch context
old_context = request.context
new_context = dict(request.context, needs_legal=True)
request.context = new_context
result = super(WebsiteSale, self).checkout_form_validate(
mode, all_form_values, data)
# Unpatch context
request.context = old_context
return result

def _checkout_form_save(self, mode, checkout, all_values):
res = super(WebsiteSale, self)._checkout_form_save(
mode, checkout, all_values)
if (all_values.get('submitted') and
all_values.get('accepted_legal_terms')):
environ = request.httprequest.headers.environ
metadata = "Website legal terms acceptance metadata: "
metadata += "<br/>".join(
"%s: %s" % (val, environ.get(val)) for val in (
"REMOTE_ADDR",
"HTTP_USER_AGENT",
"HTTP_ACCEPT_LANGUAGE",
)
)
partner_id = request.env['res.partner'].browse(res)
website_user = request.website.salesperson_id.id or SUPERUSER_ID
partner_id.sudo(website_user).message_post(
body=metadata, message_type='notification')
return res
14 changes: 14 additions & 0 deletions website_sale_require_legal/demo/assets.xml
Original file line number Diff line number Diff line change
@@ -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 (https://www.gnu.org/licenses/agpl). -->

<odoo>

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

</odoo>
28 changes: 28 additions & 0 deletions website_sale_require_legal/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_require_legal
#
# Translators:
# Rudolf Schnapka <rs@techno-flex.de>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-20 01:42+0000\n"
"PO-Revision-Date: 2017-05-20 01:42+0000\n"
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>, 2017\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: website_sale_require_legal
#: model:ir.ui.view,arch_db:website_sale_require_legal.checkout
msgid ""
"Confirm\n"
" <span class=\"fa fa-long-arrow-right\"/>"
msgstr ""
"Bestätigen\n"
" <span class=\"fa fa-long-arrow-right\"/>"
28 changes: 28 additions & 0 deletions website_sale_require_legal/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_require_legal
#
# Translators:
# Pedro M. Baeza <pedro.baeza@gmail.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-07 02:00+0000\n"
"PO-Revision-Date: 2017-01-07 02:00+0000\n"
"Last-Translator: Pedro M. Baeza <pedro.baeza@gmail.com>, 2017\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: website_sale_require_legal
#: model:ir.ui.view,arch_db:website_sale_require_legal.checkout
msgid ""
"Confirm\n"
" <span class=\"fa fa-long-arrow-right\"/>"
msgstr ""
"Confirmar\n"
" <span class=\"fa fa-long-arrow-right\"/>"
23 changes: 23 additions & 0 deletions website_sale_require_legal/i18n/hr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_require_legal
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: e-commerce (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-17 10:15+0000\n"
"PO-Revision-Date: 2016-10-04 10:07+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>\n"
"Language-Team: Croatian (http://www.transifex.com/oca/OCA-e-commerce-8-0/language/hr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: hr\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"

#. module: website_sale_require_legal
#: view:website:website_sale.checkout
msgid "Confirm"
msgstr "Potvrdi"
28 changes: 28 additions & 0 deletions website_sale_require_legal/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_require_legal
#
# Translators:
# Paolo Valier <paolo.valier@hotmail.it>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-28 02:55+0000\n"
"PO-Revision-Date: 2017-03-28 02:55+0000\n"
"Last-Translator: Paolo Valier <paolo.valier@hotmail.it>, 2017\n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: it\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: website_sale_require_legal
#: model:ir.ui.view,arch_db:website_sale_require_legal.checkout
msgid ""
"Confirm\n"
" <span class=\"fa fa-long-arrow-right\"/>"
msgstr ""
"Conferma\n"
"<span class=\"fa fa-long-arrow-right\"/>"
24 changes: 24 additions & 0 deletions website_sale_require_legal/i18n/sl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_require_legal
#
# Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2016
msgid ""
msgstr ""
"Project-Id-Version: e-commerce (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-28 00:48+0000\n"
"PO-Revision-Date: 2016-07-27 02:52+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-e-commerce-8-0/language/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"

#. module: website_sale_require_legal
#: view:website:website_sale.checkout
msgid "Confirm"
msgstr "Potrjujem"
3 changes: 3 additions & 0 deletions website_sale_require_legal/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To configure this module, you need to:

* Set up your legal pages.
7 changes: 7 additions & 0 deletions website_sale_require_legal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Rafael Blasco <rafael.blasco@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Ernesto Tejeda <ernesto.tejeda87@gmail.com>
3 changes: 3 additions & 0 deletions website_sale_require_legal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module was written to extend the functionality of your website shop to
support forcing the user to accept your legal advice, terms of use and privacy
policy, and allow you to comply with some countries' laws.
3 changes: 3 additions & 0 deletions website_sale_require_legal/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To install this module, you need to:

* Install repository `OCA/website <https://github.com/OCA/website>`_.
Copy link
Member

Choose a reason for hiding this comment

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

This is implicit, remove it please. (People get dependencies when downloading from apps.odoo.com)

Copy link
Member Author

Choose a reason for hiding this comment

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

In PR #238 @chienandalu comment something like this, and @pedrobaeza answered:
That's not true. You have to indicate dependencies outside of the current repo, which is the case.

Please, check that and confirm me what i should do, thanks.

5 changes: 5 additions & 0 deletions website_sale_require_legal/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Shopping terms and conditions are accepted only on user registration or
address edition. So if those terms change after the user signed up, a
notification should be made. An implicit acceptance could be printed in the
payment screen to solve this. Maybe that could be a work to develope in
another module.
3 changes: 3 additions & 0 deletions website_sale_require_legal/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To use this module, you need to:

* Buy something from your website.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions website_sale_require_legal/static/src/js/tour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */

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

var tour = require("web_tour.tour");

var steps = [
{
trigger: "a:contains('iPod')",
},
{
trigger: "#add_to_cart",
},
{
trigger: ".btn-primary:contains('Process Checkout')",
},
{
trigger: "a.js_edit_address:first",
},
{
trigger: ".btn-primary:contains('Next')",
},
{
trigger: ".form-group.has-error #accepted_legal_terms",
},
{
trigger: ".btn-primary:contains('Next')",
},
{
trigger: "form[action='/shop/address'] a",
},
{
trigger: ".btn-primary:contains('Next')",
},
{
trigger: ".form-group.has-error #accepted_legal_terms",
},
{
trigger: ".btn-primary:contains('Next')",
},
];

tour.register(
"website_sale_require_legal",
{
url: "/shop",
test: true,
},
steps
);

return {
steps: steps,
};
});
3 changes: 3 additions & 0 deletions website_sale_require_legal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_ui
30 changes: 30 additions & 0 deletions website_sale_require_legal/tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import HttpCase


class UICase(HttpCase):
def setUp(self):
"""Ensure website lang is en_US."""
super(UICase, self).setUp()
with self.cursor() as cr:
env = self.env(cr)
website = env["website"].get_current_website()
wiz = env["base.language.install"].create({
"lang": "en_US",
})
wiz.website_ids = website
wiz.lang_install()
website.default_lang_id = env.ref("base.lang_en")

def test_ui_website(self):
"""Test frontend tour."""
tour = "website_sale_require_legal"
self.phantom_js(
url_path="/shop",
code="odoo.__DEBUG__.services['web_tour.tour']"
".run('%s')" % tour,
ready="odoo.__DEBUG__.services['web_tour.tour']"
".tours.%s.ready" % tour,
login="admin")
25 changes: 25 additions & 0 deletions website_sale_require_legal/views/website_sale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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="accept_input">
<div t-attf-class="form-group col-md-12 #{'has-error' if error and error.get('accepted_legal_terms') else ''}">
<label for="accepted_legal_terms" class="control-label">
<input
type="checkbox"
name="accepted_legal_terms"
id="accepted_legal_terms"
required="required"/>
<t t-call="website_legal_page.acceptance_full"/>
</label>
</div>
</template>

<template id="address" inherit_id="website_sale.address">
<xpath expr="//div[hasclass('clearfix')][last()]" position="after">
<t t-call="website_sale_require_legal.accept_input"/>
</xpath>
</template>

</odoo>