From 0a13b7a7a21502ecd8cf8a3911f7a9f14eb09644 Mon Sep 17 00:00:00 2001 From: Kinjal Mehta Date: Wed, 5 Jul 2017 14:41:34 +0530 Subject: [PATCH] [IMP] product: Remove field `Category Type` on product category Purpose ======= It is possible to break the installation of any module if a module that creates a product should be installed. to reproduce: set "all" as category of one product then change "all" category to view type then install pos (because pos installs one product) you will get the error message in a traceback See https://www.odoo.com/web#id=748876&view_type=form&model=project.issue&action=963&active_id=49&menu_id=4720 Specs ===== remove "Category type" in categories it seems to me the only usefulness of this was the deprecated tree view of product categories (no longer exists) --- addons/product/models/product.py | 4 ---- addons/product/models/product_template.py | 15 ++++----------- addons/product/views/product_views.xml | 5 ++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 8e4d8955600..348e5d8881d 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -27,10 +27,6 @@ class ProductCategory(models.Model): store=True) parent_id = fields.Many2one('product.category', 'Parent Category', index=True, ondelete='cascade') child_id = fields.One2many('product.category', 'parent_id', 'Child Categories') - type = fields.Selection([ - ('view', 'View'), - ('normal', 'Normal')], 'Category Type', default='normal', - help="A category of the view type is a virtual category that can be used as the parent of another category to create a hierarchical structure.") parent_left = fields.Integer('Left Parent', index=1) parent_right = fields.Integer('Right Parent', index=1) product_count = fields.Integer( diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index efb701a6092..af1cf89c871 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -21,14 +21,12 @@ class ProductTemplate(models.Model): if self._context.get('categ_id') or self._context.get('default_categ_id'): return self._context.get('categ_id') or self._context.get('default_categ_id') category = self.env.ref('product.product_category_all', raise_if_not_found=False) - if category and category.type == 'normal': - return category.id - # fallback if no category "All" exists, because yes, users do delete default data! - category = self.env['product.category'].search([('type', '=', 'normal')], limit=1) + if not category: + category = self.env['product.category'].search([], limit=1) if category: return category.id else: - err_msg = _('You must define at least one product category (that is not a view) in order to be able to create products.') + err_msg = _('You must define at least one product category in order to be able to create products.') redir_msg = _('Go to Internal Categories') raise RedirectWarning(err_msg, self.env.ref('product.product_category_action_form').id, redir_msg) @@ -59,7 +57,7 @@ class ProductTemplate(models.Model): rental = fields.Boolean('Can be Rent') categ_id = fields.Many2one( 'product.category', 'Internal Category', - change_default=True, default=_get_default_category_id, domain="[('type','=','normal')]", + change_default=True, default=_get_default_category_id, required=True, help="Select category for the current product") currency_id = fields.Many2one( @@ -265,11 +263,6 @@ class ProductTemplate(models.Model): if len(p.product_variant_ids) == 1: p.product_variant_ids.packaging_ids = p.packaging_ids - @api.constrains('categ_id') - def _check_category(self): - if self.categ_id.type == 'view': - raise ValidationError(_("You cannot create a product with an Internal Category set as View. Please change the category or the category type.")) - @api.constrains('uom_id', 'uom_po_id') def _check_uom(self): if any(template.uom_id and template.uom_po_id and template.uom_id.category_id != template.uom_po_id.category_id for template in self): diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml index af0981744d1..8368c6beb18 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -421,9 +421,8 @@