diff options
Diffstat (limited to 'addons/account/models/account.py')
| -rw-r--r-- | addons/account/models/account.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/addons/account/models/account.py b/addons/account/models/account.py index f204abb0091..940f0a25522 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -149,6 +149,13 @@ class AccountTaxReportLine(models.Model): if self.tag_ids and (len(neg_tags) !=1 or len(pos_tags) != 1): raise ValidationError(_("If tags are defined for a tax report line, only two are allowed on it: a positive and a negative one.")) + @api.constrains('tag_name', 'country_id') + def _validate_tag_name_unicity(self): + if self.tag_name: + other_lines_with_same_tag = self.env['account.tax.report.line'].search_count([('tag_name', '=', self.tag_name), ('id', '!=', self.id), ('country_id', '=', self.country_id.id)]) + if other_lines_with_same_tag: + raise ValidationError(_("Tag name %(tag)s is used by more than one tax report line in %(country)s. Each tag name should only be used once per country.") % {'tag': self.tag_name, 'country': self.country_id.name}) + @api.onchange('parent_id') def _onchange_parent_id(self): """ If the parent of a report line is changed, the sequence of this line @@ -1411,12 +1418,12 @@ class AccountTax(models.Model): subsequent_tags = subsequent_taxes.get_tax_tags(is_refund, 'base') # Compute the tax lines - tax_repartition_lines = is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids + tax_repartition_lines = (is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids).filtered(lambda x: x.repartition_type == 'tax') repartition_lines_to_treat = len(tax_repartition_lines) total_amount = 0 - for repartition_line in tax_repartition_lines.filtered(lambda x: x.repartition_type == 'tax'): + for repartition_line in tax_repartition_lines: # In case some rounding error occurs, we compensate for it on the last line - line_amount = round(sign * tax_amount * repartition_line.factor if repartition_lines_to_treat != 1 else tax_amount - total_amount, prec) + line_amount = round(sign * tax_amount * repartition_line.factor if repartition_lines_to_treat != 1 else sign * (tax_amount - total_amount), prec) taxes_vals.append({ 'id': tax.id, |
