From 85d29c0d6552b7f892bea032cf60b7e1fd22a957 Mon Sep 17 00:00:00 2001 From: Jordi Esteve Date: Wed, 4 Jun 2014 18:44:08 +0200 Subject: [PATCH] Allow discount digits be defined in config file --- doc/es/index.rst | 15 +++++++-------- doc/index.rst | 14 +++++++++----- invoice.py | 6 ++++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/doc/es/index.rst b/doc/es/index.rst index 9aa3769..535a1ea 100644 --- a/doc/es/index.rst +++ b/doc/es/index.rst @@ -2,15 +2,14 @@ Facturación. Descuentos en las líneas de las facturas ===================================================== -En las líneas de la factura podemos añadir un valor fijo para aplicar un descuento. +Permite realizar descuentos en las líneas de la factura. -El descuento se aplica en el campo "Precio unidad" a partir del descuento y el -campo "Precio bruto". +A partir del "Descuento" y el "Precio unidad bruto" se calcula el campo "Precio unidad" como: -Precio = Precio bruto - descuento +Precio unidad = Precio unidad bruto * (1 - Descuento) -Por defecto el número de dígitos del descuento son 4 dígitos. Si desea usar más -número de dígitos en el descuento, en el fichero de configuración de trytond, -puede definir la variable "unit_price_digits" y el número de dígitos. Por ejemplo: +Por defecto el número de decimales del "Precio unidad bruto" y el "Descuento" es 4. El número de decimales del "Precio unidad" es la suma de ambos, por defecto 8. +Si desea cambiar el número de decimales del "Precio unidad bruto" y/o el "Descuento", por ejemplo 3 y 2 respectivamente, puede definir las siguientes variables en el fichero de configuración de trytond: -unit_price_digits = 8 +unit_price_digits = 3 +discount_digits = 2 diff --git a/doc/index.rst b/doc/index.rst index 2f10852..66a8d69 100755 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,10 +1,14 @@ Account Invoice Discount Module ############################### -Tryton module to add discounts in lines invoice +Tryton module to add discounts on invoice lines. -Default discount digits is 4 digits. If you like increase number digits, -in trytond configuration file you could add new variable "unit_price_digits" -and add digits value. For example: +From the "Discount" and the "Gross unit price", the "Unit price" field is calculated as: -unit_price_digits = 8 +Unit price = Gross unit price * (1 - Discount) + +By default the number of decimal places of "Gross unit price" and "Discount" is 4. The number of decimal places of "Unit Price" is the sum of both, by default 8. +To change the number of decimal places of "Gross unit price" and / or "Discount", for example 3 and 2 respectively, you can define the following variables in trytond configuration file: + +unit_price_digits = 3 +discount_digits = 2 diff --git a/invoice.py b/invoice.py index 42e518f..14e9c84 100644 --- a/invoice.py +++ b/invoice.py @@ -4,6 +4,7 @@ from trytond.pool import PoolMeta from trytond.pyson import Eval from trytond.config import CONFIG DIGITS = int(CONFIG.get('unit_price_digits', 4)) +DISCOUNT_DIGITS = int(CONFIG.get('discount_digits', 4)) __all__ = ['InvoiceLine'] __metaclass__ = PoolMeta @@ -19,13 +20,14 @@ class InvoiceLine: gross_unit_price = fields.Numeric('Gross Price', digits=(16, DIGITS), states=STATES) - discount = fields.Numeric('Discount', digits=(16, 4), states=STATES) + discount = fields.Numeric('Discount', digits=(16, DISCOUNT_DIGITS), + states=STATES) @classmethod def __setup__(cls): super(InvoiceLine, cls).__setup__() cls.unit_price.states['readonly'] = True - cls.unit_price.digits = (20, DIGITS + 4) + cls.unit_price.digits = (20, DIGITS + DISCOUNT_DIGITS) if 'discount' not in cls.amount.on_change_with: cls.amount.on_change_with.add('discount') if 'gross_unit_price' not in cls.amount.on_change_with: