[FIX] account: fix populate

Fix the populate script of account bank statements that
would try to create statement lines with an amount set to 0.
This is wrong, and also causes the populate to fail because
of a constrains

closes odoo/odoo#115597

X-original-commit: 273b99adc34d478d62d107040eae1db3ca883f6e
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Nicolas (vin)
2023-03-16 21:48:59 +01:00
parent c28ad2eae6
commit 09383bd8b3
@@ -92,6 +92,14 @@ class AccountBankStatementLine(models.Model):
partner = search_partner_ids(company_id)
return random.choices(partner + [False], [1/len(partner)] * len(partner) + [1])[0]
def get_amount(random, **kwargs):
"""Get a random amount between -1000 and 1000.
It is impossible to get a null amount. Because it would not be a valid statement line.
:param random: seeded random number generator.
:return (float): a number between -1000 and 1000.
"""
return random.uniform(-1000, 1000) or 1
def get_amount_currency(random, values, **kwargs):
"""
Get a random amount currency between one tenth of amount and 10 times amount with the same sign
@@ -129,7 +137,7 @@ class AccountBankStatementLine(models.Model):
('partner_id', populate.compute(get_partner)),
('date', populate.randdatetime(relative_before=relativedelta(years=-4))),
('payment_ref', populate.constant('transaction_{values[date]}_{counter}')),
('amount', populate.randint(-1000, 1000)),
('amount', populate.compute(get_amount)),
('foreign_currency_id', populate.compute(get_currency)),
('amount_currency', populate.compute(get_amount_currency)),
]