Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge 79ccd6d into 909ef5e
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Oct 18, 2018
2 parents 909ef5e + 79ccd6d commit 80a75ff
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 179 deletions.
23 changes: 23 additions & 0 deletions product_categ_search_complete_name/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. 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

==========================================
Product - Search On Complete Category Name
==========================================

Search the product_category on the complete name, that's to say the
name containing all parents

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

* Julien WESTE
* Sylvain LE GAL (https://twitter.com/legalsylvain)

Funders
-------

The development of this module has been financially supported by:

* GRAP, Groupement Régional Alimentaire de Proximité (http://www.grap.coop)
26 changes: 2 additions & 24 deletions product_categ_search_complete_name/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,2 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Product - Search On Complete Category Name Module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Julien WESTE
#
# 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/>.
#
##############################################################################


from . import model
# coding: utf-8
from . import models
47 changes: 11 additions & 36 deletions product_categ_search_complete_name/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Product - Search On Complete Category Name Module for Odoo
# Copyright (C) 2013-Today GRAP (http://www.grap.coop)
# @author Julien WESTE
#
# 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/>.
#
##############################################################################
# coding: utf-8
# Copyright (C) 2013 - Today: GRAP (http://www.grap.coop)
# @author: Julien WESTE
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Product - Search On Complete Category Name',
'version': '0.2',
'version': '8.0.1.0.0',
'category': 'Product',
'description': """
Search the product_category on the complete name, that's to say the
name containing all parents
===================================================================
===========================
Copyright, Author and Licence :
-------------------------------
* Copyright : 2013, Groupement Régional Alimentaire de Proximité;
* Author :
* Julien WESTE;
* Licence : AGPL-3 (http://www.gnu.org/licenses/)
""",
'author': 'GRAP',
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
'product',
],
'data': [
'view/product_view.xml',
'views/view_product_category.xml',
],
'demo': [
'demo/res_groups.xml',
'demo/product_category.xml',
],
}
18 changes: 18 additions & 0 deletions product_categ_search_complete_name/demo/product_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data>

<record id="category_parent" model="product.category">
<field name="name">Parent Category</field>
</record>

<record id="category_child" model="product.category">
<field name="name">Child Category</field>
<field name="parent_id" ref="category_parent"/>
</record>

</data></openerp>
17 changes: 17 additions & 0 deletions product_categ_search_complete_name/demo/res_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data>

<record id="base.group_sale_manager" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>

<record id="base.group_no_one" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>

</data></openerp>
23 changes: 0 additions & 23 deletions product_categ_search_complete_name/model/__init__.py

This file was deleted.

80 changes: 0 additions & 80 deletions product_categ_search_complete_name/model/product_category.py

This file was deleted.

2 changes: 2 additions & 0 deletions product_categ_search_complete_name/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding: utf-8
from . import product_category
36 changes: 36 additions & 0 deletions product_categ_search_complete_name/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding: utf-8
# Copyright (C) 2013 - Today: GRAP (http://www.grap.coop)
# @author: Julien WESTE
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from openerp import api, fields, models


class ProductCategory(models.Model):
_inherit = 'product.category'
_rec_name = 'stored_complete_name'

# Columns section
stored_complete_name = fields.Char(
string='Stored Complete Name', store=True,
compute='_compute_stored_complete_name')

# compute Section
@api.multi
@api.depends('name', 'parent_id.stored_complete_name')
def _compute_stored_complete_name(self):
for category in self:
if not category.parent_id:
category.stored_complete_name = category.name
else:
category.stored_complete_name = "%s / %s" % (
category.parent_id.stored_complete_name, category.name)

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
res = self.search(
[('stored_complete_name', operator, name)] + (args or []),
limit=limit)
return res.name_get()
Binary file not shown.
2 changes: 2 additions & 0 deletions product_categ_search_complete_name/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding: utf-8
from . import test_module
37 changes: 37 additions & 0 deletions product_categ_search_complete_name/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coding: utf-8
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class TestModule(TransactionCase):

def setUp(self):
super(TestModule, self).setUp()
self.ProductCategory = self.env['product.category']
self.category_parent = self.env.ref(
'product_categ_search_complete_name.category_parent')
self.category_child = self.env.ref(
'product_categ_search_complete_name.category_child')

# Test Section
def test_01_search_category_complete(self):
res = self.ProductCategory.name_search(
self.category_child.complete_name)

self.assertEqual(
len(res) == 1 and res[0][0],
self.category_child.id,
"Searching on complete name should succeed")

# Test Section
def test_02_search_category_partial(self):
res = self.ProductCategory.name_search(
"%s /" % self.category_parent.name)

self.assertEqual(
len(res) == 1 and res[0][0],
self.category_child.id,
"Searching on the name of the parent plus / should succeed")
16 changes: 0 additions & 16 deletions product_categ_search_complete_name/view/product_view.xml

This file was deleted.

14 changes: 14 additions & 0 deletions product_categ_search_complete_name/views/view_product_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp><data>

<record id="view_product_category_search" model="ir.ui.view">
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_search_view" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="stored_complete_name" string="Complete Name" />
</field>
</field>
</record>

</data></openerp>

0 comments on commit 80a75ff

Please sign in to comment.