[FIX] account: fix a division by zero in automatic entries
When opening automatic entries on a group of entries which sum equals to zero, a division by zero occurs which cause a traceback. This commit will fix the issue. task id #2334872 X-original-commit: bd8b81c62c4256898d579f81f066ad202f4ea79a
This commit is contained in:
@@ -49,7 +49,6 @@ class AutomaticEntryWizard(models.TransientModel):
|
||||
if not (0.0 < record.percentage <= 100.0):
|
||||
raise UserError(_("Percentage must be between 0 and 100"))
|
||||
if record.percentage != 100 and record.action != 'change_period':
|
||||
print(record.percentage)
|
||||
raise UserError(_("Percentage can only be set for Change Period method"))
|
||||
|
||||
@api.depends('percentage', 'move_line_ids')
|
||||
@@ -60,7 +59,11 @@ class AutomaticEntryWizard(models.TransientModel):
|
||||
@api.depends('total_amount', 'move_line_ids')
|
||||
def _compute_percentage(self):
|
||||
for record in self:
|
||||
record.percentage = record.total_amount / (sum(record.move_line_ids.mapped('balance')) or record.total_amount) * 100
|
||||
total = (sum(record.move_line_ids.mapped('balance')) or record.total_amount)
|
||||
if total != 0:
|
||||
record.percentage = (record.total_amount / total) * 100
|
||||
else:
|
||||
record.percentage = 100
|
||||
|
||||
@api.depends('move_line_ids')
|
||||
def _compute_account_type(self):
|
||||
|
||||
Reference in New Issue
Block a user