Add round_price
We add a common method to round prices that are stored using the price digits. It is useless to use the digits from the field because it can not be changed in any other way than by configuration. issue9146 review299521002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Add round_price
|
||||
* Make product code unique
|
||||
* Add code to template as variant prefix code
|
||||
* Hide product fields inherited from template when empty
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@ from . import uom
|
||||
from . import category
|
||||
from . import product
|
||||
from . import configuration
|
||||
from .product import price_digits
|
||||
from .product import price_digits, round_price
|
||||
from .uom import uom_conversion_digits
|
||||
|
||||
__all__ = [price_digits, uom_conversion_digits]
|
||||
__all__ = [price_digits, round_price, uom_conversion_digits]
|
||||
|
||||
|
||||
def register():
|
||||
|
||||
+7
-1
@@ -26,7 +26,7 @@ from trytond.modules.company.model import (
|
||||
from .exceptions import InvalidIdentifierCode
|
||||
|
||||
|
||||
__all__ = ['price_digits', 'TemplateFunction']
|
||||
__all__ = ['price_digits', 'round_price', 'TemplateFunction']
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TYPES = [
|
||||
@@ -42,6 +42,12 @@ COST_PRICE_METHODS = [
|
||||
price_digits = (16, config.getint('product', 'price_decimal', default=4))
|
||||
|
||||
|
||||
def round_price(value, rounding=None):
|
||||
"Round price using the price digits"
|
||||
return value.quantize(
|
||||
Decimal(1) / 10 ** price_digits[1], rounding=rounding)
|
||||
|
||||
|
||||
class Template(
|
||||
DeactivableMixin, ModelSQL, ModelView, CompanyMultiValueMixin):
|
||||
"Product Template"
|
||||
|
||||
Reference in New Issue
Block a user