Fix cost computation when date is before product creation

When product_cost_history is installed, the cost_price could be None

review373002
This commit is contained in:
Cédric Krier committed 2012-05-22 14:31:56 +02:00
1 parent d2b705a449
commit a316fa5722
2 files changed
+12 -4

No files matched your search

+6 -2
View File
@@ -191,8 +191,12 @@ class Location(ModelSQL, ModelView):
with Transaction().set_context(context):
product = product_obj.browse(product_id)
for location in self.browse(ids):
cost_values[location.id] = (Decimal(str(location.quantity))
* product.cost_price)
# The date could be before the product creation
if not isinstance(product.cost_price, Decimal):
cost_values[location.id] = None
else:
cost_values[location.id] = (Decimal(str(location.quantity))
* product.cost_price)
return cost_values
def _set_warehouse_parent(self, locations):
+6 -2
View File
@@ -164,8 +164,12 @@ class Product(ModelSQL, ModelView):
context['_datetime'] = trans_context['stock_date_end']
with Transaction().set_context(context):
for product in self.browse(ids):
cost_values[product.id] = (Decimal(str(product.quantity))
* product.cost_price)
# The date could be before the product creation
if not isinstance(product.cost_price, Decimal):
cost_values[product.id] = None
else:
cost_values[product.id] = (Decimal(str(product.quantity))
* product.cost_price)
return cost_values
def products_by_location(self, location_ids, product_ids=None,