[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)
This commit is contained in:
Kinjal Mehta
2017-07-24 11:46:09 +02:00
committed by Yannick Tivisse
parent c4ebea8cb1
commit 0a13b7a7a2
3 changed files with 6 additions and 18 deletions
-4
View File
@@ -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(
+4 -11
View File
@@ -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):
+2 -3
View File
@@ -421,9 +421,8 @@
<label for="name" string="Category name" class="oe_edit_only"/>
<h1><field name="name" placeholder="e.g. Lamps"/></h1>
</div>
<group name="first" col="4" string="Category Type">
<field name="parent_id"/>
<field name="type"/>
<group name="first" col="2">
<field name="parent_id" class="oe_inline"/>
</group>
</sheet>
</form>