diff --git a/account_tag_category/models/account.py b/account_tag_category/models/account.py index 5510aba84..b04cb22a0 100644 --- a/account_tag_category/models/account.py +++ b/account_tag_category/models/account.py @@ -11,7 +11,8 @@ class AccountAccountTag(models.Model): _inherit = 'account.account.tag' tag_category_id = fields.Many2one('account.account.tag.category', - 'tag_ids', ondelete='set null') + string='Tag category', + ondelete='set null') category_color = fields.Integer(related='tag_category_id.color') @@ -85,6 +86,10 @@ class AccountAccountTagCategory(models.Model): 'the same model as this category (%s)' ) % self.applicability) + @api.multi + def name_get(self): + return [(cat.id, cat.name) for cat in self] + class AccountAccount(models.Model): diff --git a/account_tag_category/wizard/update_tags_wizard.py b/account_tag_category/wizard/update_tags_wizard.py index acea01b68..a145c447c 100644 --- a/account_tag_category/wizard/update_tags_wizard.py +++ b/account_tag_category/wizard/update_tags_wizard.py @@ -2,7 +2,8 @@ # Copyright 2017 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError class AccountTagCategoryUpdateTags(models.TransientModel): @@ -28,6 +29,17 @@ class AccountTagCategoryUpdateTags(models.TransientModel): @api.multi def save_tags_to_category(self): + categorized_tags = self.tag_ids.filtered( + lambda t: t.tag_category_id and + t.tag_category_id != self.tag_category_id) + if categorized_tags: + tags_error = ["- %s (%s)" % (t.name, t.tag_category_id.name) + for t in categorized_tags] + raise ValidationError(_('Following tags are already defined on ' + 'another tag category : \n %s') % + "\n".join(tags_error) + ) + self.tag_category_id.write({ 'tag_ids': [(6, False, self.tag_ids.ids)] })