# Store unit\_price\_digits config setting in the database

**URL:** <https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218>\
**Category:** Ideas\
**Created:** [January 22, 2020, 3:39pm UTC](https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218 "2020-01-22T15:39:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)\
**Post date:** [January 22, 2020, 3:39pm UTC](https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218/1 "2020-01-22T15:39:51Z")

</div>

Tryton has configuration forms that are used to store most settings that affect the behaviour of the system. There’s also a configuration file but most of the time that configuration file is used for system-specific settings:

- The path of the attachments
- What IP or port it must listen to
- URI of the database
- etc

However, there’s the unit\_price\_digits setting that does not depend on the system _and_ affects the behaviour of Tryton but that is stored in trytond.conf. It seems to me that it’s easy to mess things to have unit\_price\_digits in trytond.conf and is not consistent with other settings. Otherwise, why do we store the main language in “ir.configuration”? Or why don’t we have a flag in trytond.conf to set the default invoicing policy of sales?

I think that when unit\_price\_digits was introduced it was added to the configuration file justified by performance reasons. However, I think recently we’ve seen that getting settings from the configuration file was not cheap either, and anyway we’re doing lots of other database access for getting settings (number of digits of quantities, default accounts, etc) and we even have a cache to manage all that.

So my proposal would be to store “unit\_price\_digits” as a field in “product.configuration” model.

This ensures that when you restore the database you’ve got almost everything that is necessary to make it work as the backed-up one, except, of course for the system-specific settings that cannot be “copied” from one system to the other because IPs, ports, databases, or paths will probably change.

Thoughts?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [January 22, 2020, 4:00pm UTC](https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218/2 "2020-01-22T16:00:07Z")

</div>

> [@albert](#):
>
> I think that when unit\_price\_digits was introduced it was added to the configuration file justified by performance reasons.

No, it is a configuration because it defined how the schema of the database (when digits constraint was set in the database schema).

> [@albert](#):
>
> I think recently we’ve seen that getting settings from the configuration file was not cheap either

Still way more cheaper than database access.

> [@albert](#):
>
> So my proposal would be to store “unit\_price\_digits” as a field in “product.configuration” model.

I think that storing it there will give the feeling that it can be modified at will but it is not the case. This can almost never be changed without proper migration except by increasing.  
So I think a better place would be `ir.configuration` which is not usable from UI.

Also I would prefer to avoid the creation of Function field everywhere just to be able to evaluate the digits. And also because it would give again the feeling to developer that it can be tune case by case. This must stay a global static value at least per database (or per configuration).  
So I think we should have a object that can store and fetch the value on demand. A little by like the `lazy_gettext`.

---

<div class="post-metadata">

**Author:** ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)\
**Post date:** [January 22, 2020, 4:34pm UTC](https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218/3 "2020-01-22T16:34:50Z")

</div>

> [@ced](#):
>
> I think that storing it there will give the feeling that it can be modified at will but it is not the case. This can almost never be changed without proper migration except by increasing.  
> So I think a better place would be `ir.configuration` which is not usable from UI.
> 
> Also I would prefer to avoid the creation of Function field everywhere just to be able to evaluate the digits. And also because it would give again the feeling to developer that it can be tune case by case. This must stay a global static value at least per database (or per configuration).  
> So I think we should have a object that can store and fetch the value on demand. A little by like the `lazy_gettext`

Ok. Sounds good to me.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [May 12, 2020, 10:56am UTC](https://discuss.tryton.org/t/store-unit-price-digits-config-setting-in-the-database/2218/4 "2020-05-12T10:56:04Z")

</div>

I have submitted [Check against misconfiguration of price\_digits (#9324) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue9324) which adds protection against bad configuration.
