diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/product/models/decimal_precision.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/product/models/decimal_precision.py')
| -rw-r--r-- | addons/product/models/decimal_precision.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/addons/product/models/decimal_precision.py b/addons/product/models/decimal_precision.py new file mode 100644 index 00000000..0539fbb3 --- /dev/null +++ b/addons/product/models/decimal_precision.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, tools, _ +from odoo.exceptions import ValidationError + + +class DecimalPrecision(models.Model): + _inherit = 'decimal.precision' + + @api.constrains('digits') + def _check_main_currency_rounding(self): + if any(precision.name == 'Account' and + tools.float_compare(self.env.company.currency_id.rounding, 10 ** - precision.digits, precision_digits=6) == -1 + for precision in self): + raise ValidationError(_("You cannot define the decimal precision of 'Account' as greater than the rounding factor of the company's main currency")) + return True + + @api.onchange('digits') + def _onchange_digits(self): + if self.name != "Product Unit of Measure": # precision_get() relies on this name + return + # We are changing the precision of UOM fields; check whether the + # precision is equal or higher than existing units of measure. + rounding = 1.0 / 10.0**self.digits + dangerous_uom = self.env['uom.uom'].search([('rounding', '<', rounding)]) + if dangerous_uom: + uom_descriptions = [ + " - %s (id=%s, precision=%s)" % (uom.name, uom.id, uom.rounding) + for uom in dangerous_uom + ] + return {'warning': { + 'title': _('Warning!'), + 'message': _( + "You are setting a Decimal Accuracy less precise than the UOMs:\n" + "%s\n" + "This may cause inconsistencies in computations.\n" + "Please increase the rounding of those units of measure, or the digits of this Decimal Accuracy." + ) % ('\n'.join(uom_descriptions)), + }} |
