mirror of
https://github.com/NaN-tic/trytond-sale_discount_visible.git
synced 2023-12-14 05:13:13 +01:00
Avoid precission problem computing the discount from gross unit price without rounding
This commit is contained in:
parent
2c3b1ca822
commit
bc53ede66f
|
@ -21,7 +21,7 @@ class InvoiceLine:
|
|||
'customer': self.invoice.party.id,
|
||||
}):
|
||||
Product = Pool().get('product.product')
|
||||
gross_unit_price = self.gross_unit_price
|
||||
gross_unit_price = self.gross_unit_price_wo_round
|
||||
discount = Decimal(0)
|
||||
unit_price = Product.get_sale_price([self.product],
|
||||
self.quantity or 0)[self.product.id]
|
||||
|
@ -34,7 +34,6 @@ class InvoiceLine:
|
|||
discount = discount.quantize(
|
||||
Decimal(str(10.0 ** -discount_digits)))
|
||||
return {
|
||||
'gross_unit_price': gross_unit_price,
|
||||
'discount': discount,
|
||||
'unit_price': unit_price,
|
||||
}
|
||||
|
@ -45,6 +44,7 @@ class InvoiceLine:
|
|||
if (invoice_type in ('out_invoice', 'out_credit_note') and
|
||||
'gross_unit_price' in res):
|
||||
self.gross_unit_price = res['gross_unit_price']
|
||||
self.gross_unit_price_wo_round = res['gross_unit_price_wo_round']
|
||||
res.update(self.update_prices_visible_discount())
|
||||
return res
|
||||
|
||||
|
@ -57,5 +57,7 @@ class InvoiceLine:
|
|||
res = super(InvoiceLine, self).on_change_product()
|
||||
if 'gross_unit_price' in res:
|
||||
self.gross_unit_price = res['gross_unit_price']
|
||||
self.gross_unit_price_wo_round = (
|
||||
res['gross_unit_price_wo_round'])
|
||||
res.update(self.update_prices_visible_discount())
|
||||
return res
|
||||
|
|
5
sale.py
5
sale.py
|
@ -14,6 +14,7 @@ class SaleLine:
|
|||
def update_prices_visible_discount(self):
|
||||
Product = Pool().get('product.product')
|
||||
unit_price = self.gross_unit_price
|
||||
unit_price_wo_round = self.gross_unit_price_wo_round
|
||||
discount = Decimal(0)
|
||||
gross_unit_price = Product.get_sale_price([self.product],
|
||||
self.quantity or 0)[self.product.id]
|
||||
|
@ -22,7 +23,7 @@ class SaleLine:
|
|||
discount_digits = self.__class__.discount.digits[1]
|
||||
gross_unit_price = gross_unit_price.quantize(
|
||||
Decimal(str(10.0 ** -unit_price_digits)))
|
||||
discount = 1 - (unit_price / gross_unit_price)
|
||||
discount = 1 - (unit_price_wo_round / gross_unit_price)
|
||||
discount = discount.quantize(
|
||||
Decimal(str(10.0 ** -discount_digits)))
|
||||
return {
|
||||
|
@ -35,6 +36,7 @@ class SaleLine:
|
|||
res = super(SaleLine, self).on_change_product()
|
||||
if 'gross_unit_price' in res:
|
||||
self.gross_unit_price = res['gross_unit_price']
|
||||
self.gross_unit_price_wo_round = res['gross_unit_price_wo_round']
|
||||
res.update(self.update_prices_visible_discount())
|
||||
return res
|
||||
|
||||
|
@ -42,5 +44,6 @@ class SaleLine:
|
|||
res = super(SaleLine, self).on_change_quantity()
|
||||
if 'gross_unit_price' in res:
|
||||
self.gross_unit_price = res['gross_unit_price']
|
||||
self.gross_unit_price_wo_round = res['gross_unit_price_wo_round']
|
||||
res.update(self.update_prices_visible_discount())
|
||||
return res
|
||||
|
|
Loading…
Reference in a new issue