Normalize price ratio from component quantity
The price ratio is used to convert unit price of kit into unit price of component so it must be for 1 unit or the component. issue11874 review424221004
This commit is contained in:
1 parent
85b97a94a8
commit
d37b04e558
3 files changed
+13
-5
No files matched your search
@@ -142,7 +142,7 @@ def order_mixin(prefix):
|
||||
components = []
|
||||
for component in line.product.components_used:
|
||||
components.append(line.get_component(component))
|
||||
Component.set_price_ratio(components)
|
||||
Component.set_price_ratio(components, line.quantity)
|
||||
line.components = components
|
||||
else:
|
||||
for component in line.product.components_used:
|
||||
@@ -284,7 +284,7 @@ def order_line_component_mixin(prefix):
|
||||
return self.line.product.type
|
||||
|
||||
@classmethod
|
||||
def set_price_ratio(cls, components):
|
||||
def set_price_ratio(cls, components, quantity):
|
||||
"Set price ratio between components"
|
||||
pool = Pool()
|
||||
Uom = pool.get('product.uom')
|
||||
@@ -294,7 +294,11 @@ def order_line_component_mixin(prefix):
|
||||
product = component.product
|
||||
list_price = Uom.compute_price(
|
||||
product.default_uom, product.list_price,
|
||||
component.unit) * Decimal(str(component.quantity))
|
||||
component.unit)
|
||||
if component.fixed:
|
||||
list_price *= Decimal(str(component.quantity / quantity))
|
||||
else:
|
||||
list_price *= Decimal(str(component.quantity_ratio))
|
||||
list_prices[component] = list_price
|
||||
sum_ += list_price
|
||||
|
||||
@@ -303,6 +307,10 @@ def order_line_component_mixin(prefix):
|
||||
ratio = list_prices[component] / sum_
|
||||
else:
|
||||
ratio = 1 / len(components)
|
||||
if component.fixed:
|
||||
ratio /= Decimal(str(component.quantity / quantity))
|
||||
else:
|
||||
ratio /= Decimal(str(component.quantity_ratio))
|
||||
component.price_ratio = ratio
|
||||
|
||||
def get_move(self, type_):
|
||||
|
||||
@@ -253,7 +253,7 @@ Check unit price of moves::
|
||||
>>> shipment.reload()
|
||||
>>> invoice.reload()
|
||||
>>> sorted([m.unit_price for m in shipment.incoming_moves])
|
||||
[Decimal('5.0000'), Decimal('5.0000'), Decimal('7.0909'), Decimal('18.9091')]
|
||||
[Decimal('5.0000'), Decimal('5.0000'), Decimal('9.4545'), Decimal('14.1818')]
|
||||
|
||||
Check backorder moves::
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ Check unit price of moves::
|
||||
>>> shipment.reload()
|
||||
>>> invoice.reload()
|
||||
>>> sorted([m.unit_price for m in shipment.outgoing_moves])
|
||||
[Decimal('10.0000'), Decimal('10.0000'), Decimal('15.0000'), Decimal('25.0000')]
|
||||
[Decimal('10.0000'), Decimal('10.0000'), Decimal('25.0000'), Decimal('37.5000')]
|
||||
|
||||
Check backorder::
|
||||
|
||||
|
||||
Reference in new issue
Block a user