summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRichard Mathot <rim@odoo.com>2017-07-10 10:45:28 +0200
committerRichard Mathot <rim@odoo.com>2017-07-10 10:46:47 +0200
commit9e08da51efd21eeab8ebfa372caff8d10fb253df (patch)
tree196652e8e6f9e5acfdd4bd2aa62db9e5ca23a0b0 /addons
parent514a1a76d81de3943f752ceaa5e487a2d25b9bb7 (diff)
[FIX] product: allow to create products even when dumb people do delete default category
(or at least give 'em a hint on what's happening) opw-751701
Diffstat (limited to 'addons')
-rw-r--r--addons/product/models/product_template.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index 93939587ee0..c812c7d9245 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -7,7 +7,7 @@ import psycopg2
import odoo.addons.decimal_precision as dp
from odoo import api, fields, models, tools, _
-from odoo.exceptions import ValidationError, except_orm
+from odoo.exceptions import ValidationError, RedirectWarning, except_orm
class ProductTemplate(models.Model):
@@ -20,7 +20,16 @@ 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)
- return category.id if category.type == 'normal' else 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 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.')
+ redir_msg = _('Go to Internal Categories')
+ raise RedirectWarning(err_msg, self.env.ref('product.product_category_action_form').id, redir_msg)
def _get_default_uom_id(self):
return self.env["product.uom"].search([], limit=1, order='id').id