changeset f2c540142dd5 in modules/product_kit:6.0 details: https://hg.tryton.org/modules/product_kit?cmd=changeset&node=f2c540142dd5 description: 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 (grafted from 3127dbf9cd1537f07181161779d9bff7c0d3ebcb) diffstat: common.py | 14 +++++++++++--- tests/scenario_product_kit_purchase.rst | 2 +- tests/scenario_product_kit_sale.rst | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diffs (69 lines): diff -r 778b61c43f84 -r f2c540142dd5 common.py --- a/common.py Thu Nov 17 18:58:56 2022 +0100 +++ b/common.py Thu Nov 24 19:19:50 2022 +0100 @@ -129,7 +129,7 @@ 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: @@ -272,7 +272,7 @@ 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') @@ -282,7 +282,11 @@ 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 @@ -291,6 +295,10 @@ 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_): diff -r 778b61c43f84 -r f2c540142dd5 tests/scenario_product_kit_purchase.rst --- a/tests/scenario_product_kit_purchase.rst Thu Nov 17 18:58:56 2022 +0100 +++ b/tests/scenario_product_kit_purchase.rst Thu Nov 24 19:19:50 2022 +0100 @@ -253,7 +253,7 @@ >>> 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:: diff -r 778b61c43f84 -r f2c540142dd5 tests/scenario_product_kit_sale.rst --- a/tests/scenario_product_kit_sale.rst Thu Nov 17 18:58:56 2022 +0100 +++ b/tests/scenario_product_kit_sale.rst Thu Nov 24 19:19:50 2022 +0100 @@ -236,7 +236,7 @@ >>> 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::