From 5d96a5f234efa80ae242188e375e96ae64f6ed9f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 21 Sep 2015 21:40:05 +0200 Subject: [PATCH] [IMP] purchase: multiple improvements 1) Remove unnecessary comparison If the minimum quantity required by the supplier is not met, the supplier is not chosen. So it is not necessary to compare the quantity of the supplier after the browse. 2) Ignore AccessError when adding to new supplier to product This should not block the user to confirm the PO. --- addons/purchase/purchase.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 91ef9dcb4e2..50e961d880a 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -8,7 +8,7 @@ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.tools.translate import _ from openerp.tools.float_utils import float_is_zero, float_compare import openerp.addons.decimal_precision as dp -from openerp.exceptions import UserError +from openerp.exceptions import UserError, AccessError class PurchaseOrder(models.Model): _name = "purchase.order" @@ -352,8 +352,10 @@ class PurchaseOrder(models.Model): vals = { 'seller_ids': [(0, 0, supplierinfo)], } - line.product_id.write(vals) - + try: + line.product_id.write(vals) + except AccessError: # no write access rights -> just ignore + break class PurchaseOrderLine(models.Model): _name = 'purchase.order.line' @@ -587,11 +589,6 @@ class PurchaseOrderLine(models.Model): 'quantity': quantity_seller_uom_id, }) - # Switch quantity back in product_uom - quantity = max(quantity_seller_uom_id, product.seller_qty) - if quantity and seller_product_uom != product_uom: - quantity = seller_product_uom._compute_qty_obj(seller_product_uom, quantity, product_uom) - price_unit = product.seller_price if price_unit and seller_currency_id != currency_id: price_unit = seller_currency_id.compute(price_unit, currency_id)