[FIX] purchase: use proper uom and currency

The UoM and the currency of a product depends on the vendor. Therefore,
before searching for the price and minimum quantity we need to know
this information in order to do a correct comparison.
This commit is contained in:
Nicolas Martinelli
2015-09-06 22:03:23 +02:00
parent b0c06e21e3
commit 367cacfc7e
5 changed files with 38 additions and 10 deletions
+24 -10
View File
@@ -553,26 +553,40 @@ class PurchaseOrderLine(models.Model):
:rtype: dict
:return: name, seller quantity, seller price, date planned
"""
# Switch quantity in uom_id
quantity_uom_id = quantity
if quantity_uom_id and product_id.uom_id != product_uom:
quantity_uom_id = product_uom._compute_qty_obj(product_uom, quantity_uom_id, product_id.uom_id)
# This is useful in case partner is not registered supplier
if not product_id or not partner_id or not product_uom or not currency_id:
return {
'name': False,
'quantity': 0.0,
'price_unit': 0.0,
'date_planned': False,
}
# The first browse is used to know the uom_id and the currency_id for the given vendor
product = product_id.with_context({'partner_id': partner_id.id})
seller_currency_id = product.selected_seller_id.currency_id if product.selected_seller_id else partner_id.currency_id
seller_product_uom = product.selected_seller_id.product_uom if product.selected_seller_id else product_id.uom_id
# Switch quantity to uom_id
quantity_seller_uom_id = quantity
if quantity_seller_uom_id and seller_product_uom != product_uom:
quantity_seller_uom_id = product_uom._compute_qty_obj(product_uom, quantity_seller_uom_id, seller_product_uom)
product = product_id.with_context({
'lang': partner_id.lang,
'partner_id': partner_id.id,
'date': date,
'quantity': quantity_uom_id,
'quantity': quantity_seller_uom_id,
})
# Switch quantity back in product_uom
quantity = max(quantity_uom_id, product.seller_qty)
if quantity and product_id.uom_id != product_uom:
quantity = product_id.uom_id._compute_qty_obj(product_id.uom_id, quantity, 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 partner_id.currency_id != currency_id:
price_unit = partner_id.currency_id.compute(price_unit, currency_id)
if price_unit and seller_currency_id != currency_id:
price_unit = seller_currency_id.compute(price_unit, currency_id)
date_planned = self._get_date_planned(product, po=order_id).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
+3
View File
@@ -24,6 +24,7 @@
product_uom: product.product_uom_kgm
price_unit: 60.0
name: 'Average Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-
@@ -58,6 +59,7 @@
product_uom: product.product_uom_kgm
price_unit: 80.0
name: 'Average Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the second purchase order
-
@@ -112,6 +114,7 @@
product_uom: product.product_uom_gram
price_unit: 0.2
name: 'Average Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-
+7
View File
@@ -32,6 +32,7 @@
product_uom: product.product_uom_kgm
price_unit: 50.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-
@@ -64,6 +65,7 @@
product_uom: product.product_uom_kgm
price_unit: 80.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the second purchase order
-
@@ -166,10 +168,13 @@
product_uom: product.product_uom_gram
price_unit: 0.150
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
- product_id: product_fifo_icecream
product_qty: 10.0
product_uom: product.product_uom_kgm
price_unit: 150.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the purchase order in USD
-
@@ -326,6 +331,7 @@
product_uom: product.product_uom_kgm
price_unit: 50.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-
@@ -354,6 +360,7 @@
product_uom: product.product_uom_kgm
price_unit: 80
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the second negative purchase order
-
+2
View File
@@ -25,6 +25,7 @@
product_uom: product.product_uom_kgm
price_unit: 50.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I create a draft Purchase Order for second shipment for 30 kg at 80 euro
-
@@ -36,6 +37,7 @@
product_uom: product.product_uom_kgm
price_unit: 80.0
name: 'FIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-
@@ -38,6 +38,7 @@
product_uom: product.product_uom_kgm
price_unit: 60.0
name: 'LIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I create a draft Purchase Order for second shipment for 30 pieces at 80 euro
-
@@ -49,6 +50,7 @@
product_uom: product.product_uom_kgm
price_unit: 80.0
name: 'LIFO Ice Cream'
date_planned: !eval time.strftime('%Y-%m-%d')
-
I confirm the first purchase order
-