如何根据另一个字段记录更改金额小数位数

问题描述 投票:0回答:0

如何根据字段decimal_digit记录更改数量字段小数位数

class AccountAnalyticInvoiceLine(models.Model):
    _inherit = 'account.analytic.invoice.line'
    quantity = fields.Float(digits=(16, 2)
class AccountInvoice(models.Model):
    _inherit = 'account.invoice'
    
    decimal_digit = fields.Integer(string='Decimal Digit', default=2)

我试过了

@api.onchange('decimal_digits')
    def _onchange_decimal_digits(self):
        for record in self:
            record.quantity = round(record.quantity, record.decimal_digits)

但是好像不行

python odoo odoo-11
© www.soinside.com 2019 - 2024. All rights reserved.