From 6c6a9f3d609765111e50af0656f637b30724de84 Mon Sep 17 00:00:00 2001
From: Christophe Simonis <chs@odoo.com>
Date: Thu, 26 May 2016 13:05:46 +0200
Subject: [PATCH] [FIX] *: replace uses of `except_osv` with `UserError` that
 have been forgotten during previous forward-ports

---
 addons/crm/base_partner_merge.py            | 2 +-
 addons/point_of_sale/point_of_sale.py       | 2 +-
 addons/purchase/purchase.py                 | 5 ++---
 addons/sale_stock/sale_stock.py             | 2 +-
 addons/stock/wizard/stock_return_picking.py | 2 +-
 addons/stock_account/product.py             | 2 +-
 addons/stock_account/stock_account.py       | 2 +-
 openerp/addons/base/res/res_users.py        | 2 +-
 8 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/addons/crm/base_partner_merge.py b/addons/crm/base_partner_merge.py
index 8baf69a5a7a7..95ad18f044f1 100644
--- a/addons/crm/base_partner_merge.py
+++ b/addons/crm/base_partner_merge.py
@@ -306,7 +306,7 @@ class MergePartnerAutomatic(osv.TransientModel):
         for partner_id in partner_ids:
             child_ids = child_ids.union(set(proxy.search(cr, uid, [('id', 'child_of', [partner_id])])) - set([partner_id]))
         if set(partner_ids).intersection(child_ids):
-            raise osv.except_osv(_('Error'), _("You cannot merge a contact with one of his parent."))
+            raise UserError(_("You cannot merge a contact with one of his parent."))
 
         if openerp.SUPERUSER_ID != uid and len(set(partner.email for partner in proxy.browse(cr, uid, partner_ids, context=context))) > 1:
             raise UserError(_("All contacts must have the same email. Only the Administrator can merge contacts with different emails."))
diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py
index ead3b4ac1194..9ddbc244051a 100644
--- a/addons/point_of_sale/point_of_sale.py
+++ b/addons/point_of_sale/point_of_sale.py
@@ -1546,7 +1546,7 @@ class product_template(osv.osv):
         product_ctx = dict(context or {}, active_test=False)
         if self.search_count(cr, uid, [('id', 'in', ids), ('available_in_pos', '=', True)], context=product_ctx):
             if self.pool['pos.session'].search_count(cr, uid, [('state', '!=', 'closed')], context=context):
-                raise osv.except_osv(_('Error!'),
+                raise UserError(
                     _('You cannot delete a product saleable in point of sale while a session is still opened.'))
         return super(product_template, self).unlink(cr, uid, ids, context=context)
 
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index 446da4cf081b..15226a4022b7 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -435,7 +435,7 @@ class purchase_order(osv.osv):
 
         company_id = context.get('company_id') or self.pool.get('res.users')._get_company(cr, uid, context=context)
         if not company_id:
-            raise osv.except_osv(_('Error!'), _('There is no default company for the current user!'))
+            raise UserError(_('There is no default company for the current user!'))
         fp = self.pool['account.fiscal.position'].get_fiscal_position(cr, uid, company_id, partner_id, context=context)
         supplier_address = partner.address_get(cr, uid, [partner_id], ['default'], context=context)
         supplier = partner.browse(cr, uid, partner_id, context=context)
@@ -578,8 +578,7 @@ class purchase_order(osv.osv):
             if not any(line.state != 'cancel' for line in po.order_line):
                 raise UserError(_('You cannot confirm a purchase order without any purchase order line.'))
             if po.invoice_method == 'picking' and not any([l.product_id and l.product_id.type in ('product', 'consu') and l.state != 'cancel' for l in po.order_line]):
-                raise osv.except_osv(
-                    _('Error!'),
+                raise UserError(
                     _("You cannot confirm a purchase order with Invoice Control Method 'Based on incoming shipments' that doesn't contain any stockable item."))
             for line in po.order_line:
                 if line.state=='draft':
diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py
index 65f37e985e36..f3fc9b6d3ee9 100644
--- a/addons/sale_stock/sale_stock.py
+++ b/addons/sale_stock/sale_stock.py
@@ -375,7 +375,7 @@ class sale_order_line(osv.osv):
         for procurement in lines.mapped('procurement_ids'):
             for move in procurement.move_ids:
                 if move.state == 'done' and not move.scrapped:
-                    raise osv.except_osv(_('Invalid Action!'), _('You cannot cancel a sale order line which is linked to a stock move already done.'))
+                    raise UserError(_('You cannot cancel a sale order line which is linked to a stock move already done.'))
         return super(sale_order_line, self).button_cancel(cr, uid, ids, context=context)
 
 class stock_move(osv.osv):
diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py
index ce46f07f7648..39e588bfd7ca 100644
--- a/addons/stock/wizard/stock_return_picking.py
+++ b/addons/stock/wizard/stock_return_picking.py
@@ -60,7 +60,7 @@ class stock_return_picking(osv.osv_memory):
             context = {}
         if context and context.get('active_ids', False):
             if len(context.get('active_ids')) > 1:
-                raise osv.except_osv(_('Warning!'), _("You may only return one picking at a time!"))
+                raise UserError(_("You may only return one picking at a time!"))
         res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
         record_id = context and context.get('active_id', False) or False
         uom_obj = self.pool.get('product.uom')
diff --git a/addons/stock_account/product.py b/addons/stock_account/product.py
index 728ea544a077..fd4332793487 100644
--- a/addons/stock_account/product.py
+++ b/addons/stock_account/product.py
@@ -134,7 +134,7 @@ class product_template(osv.osv):
                         if not counterpart_account:
                             counterpart_account = product.categ_id.property_account_expense_categ and product.categ_id.property_account_expense_categ.id or False
                         if not counterpart_account:
-                            raise osv.except_osv(_('Error!'), _('No expense account defined on the product %s or on its category') % (product.name))
+                            raise UserError(_('No expense account defined on the product %s or on its category') % (product.name))
                         if diff * qty > 0:
                             amount_diff = qty * diff
                             debit_account_id = counterpart_account
diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py
index bee410ae3ca7..237da2f677a8 100644
--- a/addons/stock_account/stock_account.py
+++ b/addons/stock_account/stock_account.py
@@ -196,7 +196,7 @@ class stock_quant(osv.osv):
 
         :param context: context dictionary that can explicitly mention the company to consider via the 'force_company' key
         :returns: journal_id, source account, destination account, valuation account
-        :raise: osv.except_osv() is any mandatory account or journal is not defined.
+        :raise: openerp.exceptions.UserError if any mandatory account or journal is not defined.
         """
         product_obj = self.pool.get('product.template')
         accounts = product_obj.get_product_accounts(cr, uid, move.product_id.product_tmpl_id.id, context)
diff --git a/openerp/addons/base/res/res_users.py b/openerp/addons/base/res/res_users.py
index dda40e32d7fe..38625280089e 100644
--- a/openerp/addons/base/res/res_users.py
+++ b/openerp/addons/base/res/res_users.py
@@ -527,7 +527,7 @@ class res_users(osv.osv):
 
         :return: True
         :raise: openerp.exceptions.AccessDenied when old password is wrong
-        :raise: except_osv when new password is not set or empty
+        :raise: openerp.exceptions.UserError when new password is not set or empty
         """
         self.check(cr.dbname, uid, old_passwd)
         if new_passwd:
-- 
GitLab