Skip to content
Permalink
Browse files

⬆️1️⃣1️⃣ website_sale_search_tags: port from 10.0

  • Loading branch information...
em230418 committed Jul 18, 2019
1 parent 6d23e5f commit 9c4d390fabd7ca5380c61243929e81adbb4f2091
@@ -3,4 +3,4 @@ Website Sale Search Tags

* adds results from searching by tags

Tested on Odoo 10.0 854eb97b2ef371b70c49ebe6ba39e431bfb74fe3
Tested on Odoo 11.0 7f54a246b722086db4b7e055925fbcd7ca035fea
@@ -2,13 +2,13 @@
'name': "Website Search Product Tags",
'summary': """Search website products by tags""",
'category': 'eCommerce',
'version': '11.0.1.0.2',
'version': '11.0.1.0.3',
'application': False,
'author': 'IT-Projects LLC, Ivan Yelizariev, Savoir-faire Linux, '
'Quartile Limited Tim Lai',
'Quartile Limited Tim Lai, Eugene Molotov',
'license': 'GPL-3',
"support": "apps@it-projects.info",
'website': 'https://twitter.com/yelizariev',
'website': 'https://it-projects.info',
'price': 30.0,
'currency': 'EUR',
'images': ['images/search.png'],
@@ -19,4 +19,7 @@

'auto_install': False,
'installable': False,
'data': [
'views/tours.xml',
],
}
@@ -1,3 +1,8 @@
`1.0.3`
-------

- **FIX:** incorrect domain modification in product search query

`1.0.2`
-------

@@ -0,0 +1,20 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_search_tags
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_sale_search_tags
#: model:ir.model,name:website_sale_search_tags.model_product_template
msgid "Product Template"
msgstr ""

@@ -7,8 +7,14 @@ class Product(models.Model):
def _extend_domain(self, domain):
if (self.env.context.get('search_tags') and
('tag_ids', 'ilike', self.env.context.get('search_tags')) not in domain):
domain.insert(domain.index(('sale_ok', '=', True)) + 1, '|')
domain += [('tag_ids', 'ilike', self.env.context.get('search_tags'))]

# calculating position, after which domain new domains must be placed
i = domain.index(('sale_ok', '=', True)) + 1
while type(domain[i]) in [tuple, list] and i < len(domain):
i = i + 1

domain.insert(i, '|')
domain.insert(i + 1, ('tag_ids', 'ilike', self.env.context.get('search_tags')))
return domain

@api.model
@@ -0,0 +1,41 @@
odoo.define('website_sale_search_tags.tour', function (require) {
'use strict';

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

tour.register('website_sale_search_tags', {
test: true,
url: '/shop',
wait_for: base.ready()
},
[
// for unsigned user
{
content: "type to search Apple Wireless Keyboard",
trigger: 'form input[name="search"]',
run: "text Apple Wireless Keyboard",
},
{
content: "search Apple Wireless Keyboard",
trigger: 'form:has(input[name="search"]) .oe_search_button',
},
{
content: "make sure that Apple Wireless Keyboard is founded and type to search iMac",
extra_trigger: '.oe_product_cart:eq(0) a:contains("Apple Wireless Keyboard")',
trigger: 'form input[name="search"]',
run: "text iMac",
},
{
content: "search iMac",
trigger: 'form:has(input[name="search"]) .oe_search_button',
},
{
content: "make sure that iMac is founded",
extra_trigger: '.oe_product_cart:eq(0) a:contains("iMac")',
trigger: 'form input[name="search"]',
run: "text OK!",
}
]
);
});
@@ -0,0 +1 @@
from . import test_search_tags
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

import odoo.tests


@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):

def test_search_tags(self):
# delay is added to be sure that all elements have been rendered properly
self.phantom_js("/", "odoo.__DEBUG__.services['web_tour.tour'].run('website_sale_search_tags', 500)",
"odoo.__DEBUG__.services['web_tour.tour'].tours.website_sale_search_tags.ready",
login='admin')


@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestModels(odoo.tests.SingleTransactionCase):

def test_extend_domain(self):
before = [
'|', ('company_id', '=', 1), ('company_id', '=', False),
'&', ('sale_ok', '=', True), ('event_ok', '=', False),
'|', '|', '|',
('name', 'ilike', u'iMac'),
('description', 'ilike', u'iMac'),
('description_sale', 'ilike', u'iMac'),
('product_variant_ids.default_code', 'ilike', u'iMac')
]

expected_after = [
'|', ('company_id', '=', 1), ('company_id', '=', False),
'&', ('sale_ok', '=', True), ('event_ok', '=', False),
'|', ('tag_ids', 'ilike', u'Example'), # this is added after _extend_domain
'|', '|', '|',
('name', 'ilike', u'iMac'),
('description', 'ilike', u'iMac'),
('description_sale', 'ilike', u'iMac'),
('product_variant_ids.default_code', 'ilike', u'iMac')
]

p = self.env['product.template'].create({"name": "test"})
p.env.context = {'search_tags': u'Example'}
self.assertEqual(p._extend_domain(before), expected_after)
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" name="website_sale_search_tags assets" inherit_id="website_sale.assets_frontend">
<xpath expr="." position="inside">
<script src="/website_sale_search_tags/static/src/js/website_sale_search_tags_tour.js" type="text/javascript"></script>
</xpath>
</template>
</odoo>

0 comments on commit 9c4d390

Please sign in to comment.
You can’t perform that action at this time.