From 09383bd8b3b79919a8ea3befc7944d7ed4685c81 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Thu, 16 Mar 2023 13:19:03 +0000 Subject: [PATCH] [FIX] account: fix populate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/account/populate/account_bank_statement.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/account/populate/account_bank_statement.py b/addons/account/populate/account_bank_statement.py index 1be81db8c7d..5c7cfe44424 100644 --- a/addons/account/populate/account_bank_statement.py +++ b/addons/account/populate/account_bank_statement.py @@ -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)), ]