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

[12.0] Migration: product_tags #763

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion product_tags/__init__.py
Expand Up @@ -2,6 +2,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
# Copyright (c) 2019 Matteo Bilotta <mbilotta@linkgroup.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,4 +19,4 @@
#
#

from . import product
from . import models
15 changes: 8 additions & 7 deletions product_tags/__manifest__.py
Expand Up @@ -3,6 +3,7 @@
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
# Copyright (C) 2015 credativ ltd. <info@credativ.co.uk>
# Copyright (c) 2019 Matteo Bilotta <mbilotta@linkgroup.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -21,19 +22,19 @@

{
"name": "Product Tags",
"version": "10.0.1.0.1",
"version": "12.0.1.1.0",
"author": "Julius Network Solutions",
"website": "http://julius.fr",
"category": "Sales Management",
"category": "Sales",
"depends": [
'product',
'sale',
'sale'
],
'license': 'AGPL-3',
"demo": [],
"data": [
'security/ir.model.access.csv',
'product_view.xml',
],
'installable': False,

'views/product_tag_view.xml',
'views/product_template_view.xml'
]
}
8 changes: 8 additions & 0 deletions product_tags/doc/changelog.rst
@@ -1,4 +1,12 @@
`1.1.0`
-------

- **Successful migration to Odoo 12.**
- Improved tag searching algorithm.
- Enhanced tag views for a better UX.

`1.0.1`
-------

- **Fix:** issue with search for non-existent tags

Expand Down
147 changes: 147 additions & 0 deletions product_tags/i18n/it.po
@@ -0,0 +1,147 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_tags
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0+e-20190417\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-06-21 13:41+0000\n"
"PO-Revision-Date: 2019-06-21 15:42+0200\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Language: it\n"
"X-Generator: Poedit 2.2.3\n"

#. module: product_tags
#: model_terms:ir.ui.view,arch_db:product_tags.product_tag_form_view
msgid "Accessories & Supplies"
msgstr "Accessori & Forniture"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__active
msgid "Active"
msgstr "Attivo"

#. module: product_tags
#: model_terms:ir.ui.view,arch_db:product_tags.product_tag_search_view
msgid "Archived"
msgstr "Archiviati"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__child_ids
msgid "Child tags"
msgstr "Tag figli"

#. module: product_tags
#: model_terms:ir.actions.act_window,help:product_tags.product_tag_action
msgid "Click to create a new product tag."
msgstr "Clicca per creare un nuovo tag di prodotto."

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__color
msgid "Color index"
msgstr "Indice colore"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__create_uid
msgid "Created by"
msgstr "Creato da"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__create_date
msgid "Created on"
msgstr "Creato il"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: product_tags
#: model_terms:ir.ui.view,arch_db:product_tags.product_tag_form_view
msgid "Electronics"
msgstr "Elettronica"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__id
msgid "ID"
msgstr "ID"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__image
msgid "Image"
msgstr "Immagine"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__write_uid
msgid "Last Updated by"
msgstr "Ultimo aggiornamento di"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__write_date
msgid "Last Updated on"
msgstr "Ultimo aggiornamento il"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__parent_id
msgid "Parent tag"
msgstr "Tag superiore"

#. module: product_tags
#: model:ir.model,name:product_tags.model_product_template
msgid "Product Template"
msgstr "Modello prodotto"

#. module: product_tags
#: model:ir.model,name:product_tags.model_product_tag
msgid "Product tags"
msgstr "Tag prodotti"

#. module: product_tags
#: model:ir.model.fields,field_description:product_tags.field_product_tag__name
msgid "Tag Name"
msgstr "Nome tag"

#. module: product_tags
#: model:ir.actions.act_window,name:product_tags.product_tag_action
#: model:ir.model.fields,field_description:product_tags.field_product_product__tag_ids
#: model:ir.model.fields,field_description:product_tags.field_product_template__tag_ids
#: model:ir.ui.menu,name:product_tags.product_tag_menu_sale
#: model_terms:ir.ui.view,arch_db:product_tags.product_template_search_view
msgid "Tags"
msgstr "Tag"

#. module: product_tags
#: model_terms:ir.ui.view,arch_db:product_tags.product_template_form_view
msgid "Tags..."
msgstr "Tags..."

#. module: product_tags
#: model:ir.model.fields,help:product_tags.field_product_tag__active
msgid "The active field allows you to hide the tag without removing it."
msgstr "Il campo \"Attivo\" ti consente di nascondere il tag prodotto senza rimuoverlo fisicamente."

#. module: product_tags
#: model_terms:ir.actions.act_window,help:product_tags.product_tag_action
msgid ""
"With product tags you can categorize your products\n"
" regardless of the category they belong to."
msgstr ""
"Con i tag prodotti puoi categorizzare i tuoi prodotti\n"
" indipendentemente dalla categoria a cui appartengono."

#. module: product_tags
#: code:addons/product_tags/models/product.py:45
#, python-format
msgid "You cannot create recursive product tags."
msgstr "Non puoi creare tag prodotti ricorsivi."
22 changes: 22 additions & 0 deletions product_tags/models/__init__.py
@@ -0,0 +1,22 @@
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
# Copyright (c) 2019 Matteo Bilotta <mbilotta@linkgroup.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#

from . import product
71 changes: 44 additions & 27 deletions product_tags/product.py → product_tags/models/product.py
Expand Up @@ -3,6 +3,7 @@
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
# Copyright (C) 2015 credativ ltd. <info@credativ.co.uk>
# Copyright (c) 2019 Matteo Bilotta <mbilotta@linkgroup.it>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -18,51 +19,67 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
from openerp import api
from openerp import fields
from openerp import models
from odoo import _, api, fields, models
from odoo.osv import expression
from odoo.exceptions import ValidationError


class ProductTag(models.Model):
_description = 'Product Tags'
_name = "product.tag"
_name = 'product.tag'
_description = "Product tags"
_order = 'name'
_parent_order = 'name'
_parent_store = True

name = fields.Char('Tag Name', required=True, translate=True)
active = fields.Boolean(help='The active field allows you to hide the tag without removing it.', default=True)
color = fields.Integer(string="Color index", default=0)
image = fields.Binary(sintrg="Image")

parent_id = fields.Many2one(string='Parent Tag', comodel_name='product.tag', index=True, ondelete='cascade')
child_ids = fields.One2many(string='Child Tags', comodel_name='product.tag', inverse_name='parent_id')
parent_left = fields.Integer('Left Parent', index=True)
parent_right = fields.Integer('Right Parent', index=True)
parent_path = fields.Char(index=True)

image = fields.Binary('Image')

_parent_store = True
_parent_order = 'name'
_order = 'parent_left'
@api.constrains('parent_id')
def _check_parent_id(self):
if not self._check_recursion():
raise ValidationError(_("You cannot create recursive product tags."))

@api.multi
def name_get(self):
""" Return the tags' display name, including their direct parent. """
res = {}
for record in self:
current = record
name = current.name
while current.parent_id:
name = '%s / %s' % (current.parent_id.name, name)
res = []

for category in self:
names = []
current = category

while current:
names.append(current.name)
current = current.parent_id
res[record.id] = name

return list(res.items())
res.append((category.id, ' / '.join(reversed(names))))

return res

@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
args = args or []

if name:
# Be sure name_search is symetric to name_get
name = name.split(' / ')[-1]
args = [('name', operator, name)] + args
tags = self.search(args, limit=limit)
return tags.name_get()
parent_ids = []
parent_domain = []

for tag in map(lambda t: t.strip(), name.split('/')):
name_domain = expression.AND([[('name', operator, tag)], parent_domain])
parent_ids = self._search(name_domain, limit=limit, access_rights_uid=name_get_uid)
parent_domain = [('parent_id', 'in', parent_ids)]

browse_domain = expression.OR([[('id', 'in', parent_ids)], parent_domain])
args = expression.AND([browse_domain, args])

tag_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid)

return self.browse(tag_ids).name_get()


class ProductTemplate(models.Model):
Expand Down