Deal with variable discount digits

This commit is contained in:
Jordi Esteve 2014-06-04 18:57:14 +02:00
parent de63b7b9d4
commit 22f55a7388
3 changed files with 13 additions and 13 deletions

View File

@ -1,10 +1,7 @@
==========================================================
Ventas. Precio venta y el precio de tarifa en el descuento
==========================================================
========================================================================
Ventas. Descuento calculado a partir del precio venta y precio de tarifa
========================================================================
Permite mostrar el precio de venta (precio venta sin aplicar la tarifa) con un descuento.
El descuento es la diferencia entre el precio de venta y el precio con la tarifa de venta
que se le aplica.
Permite mostrar la diferencia entre el precio de venta del producto (precio de venta sin aplicar la tarifa) y el precio de venta calculado con la tarifa en forma de descuento.
El descuento es la diferencia porcentual entre el precio de venta del producto y el precio de venta calculado con la tarifa que se le aplica.
Visualmente el cliente verá el precio que debe pagar pero con el descuento quedará con el precio
que se le aplica con la tarifa tanto a pedidos de venta como facturas.

View File

@ -1,4 +1,5 @@
Sale Discount Visible Module
############################
Tryton module that allows to show discounts in sale and invoice lines
Displays the difference between the sale price of the product (sale price without applying the pricelist) and the sale price calculated by the pricelist as the discount rate.
The discount is the percentage difference between the sale price of the product and the sale price calculated by the pricelist applied to it.

10
sale.py
View File

@ -19,11 +19,13 @@ class SaleLine:
gross_unit_price = Product.get_sale_price([self.product],
self.quantity or 0)[self.product.id]
if gross_unit_price:
unit_price_digits = self.__class__.gross_unit_price.digits[1]
discount_digits = self.__class__.discount.digits[1]
res['gross_unit_price'] = gross_unit_price.quantize(
Decimal(1) / 10 ** self.__class__.unit_price.digits[1])
discount = 1 - (res['unit_price'] /
res['gross_unit_price'])
res['discount'] = Decimal("%0.4f" % discount)
Decimal(str(10.0 ** -unit_price_digits)))
discount = 1 - (res['unit_price'] / res['gross_unit_price'])
res['discount'] = discount.quantize(
Decimal(str(10.0 ** -discount_digits)))
else:
res = super(SaleLine, self).update_prices()
return res