From 6c67d2958c78ef236280663c948f24b428204a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Feb 2025 13:08:22 +0100 Subject: [PATCH] Invert sign of budget amount As budget is based on income statement, the amount must be credit - debit. Closes #13764 --- doc/migration.rst | 12 ++++++++ modules/account_budget/CHANGELOG | 1 + modules/account_budget/account.py | 4 +-- .../tests/scenario_account_budget.rst | 30 +++++++++---------- modules/analytic_budget/CHANGELOG | 1 + modules/analytic_budget/analytic_account.py | 2 +- .../tests/scenario_analytic_budget.rst | 14 ++++----- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/doc/migration.rst b/doc/migration.rst index c2c58d08bc..74ff1af5f6 100644 --- a/doc/migration.rst +++ b/doc/migration.rst @@ -46,6 +46,18 @@ After Shipment.save(shipments) transaction.commit() +* If ``account_budget`` module is activated, invert amount sign: + + .. code-block:: SQL + + UPDATE "account_budget_line" SET amount = -amount; + +* If ``analytic_budget`` module is activated, invert amount sign: + + .. code-block:: SQL + + UPDATE "analytic_account_budget_line" SET amount = -amount; + 7.4 --- diff --git a/modules/account_budget/CHANGELOG b/modules/account_budget/CHANGELOG index ff3627c058..b45e3ea790 100644 --- a/modules/account_budget/CHANGELOG +++ b/modules/account_budget/CHANGELOG @@ -1,3 +1,4 @@ +* Invert sign of budget amount Version 7.4.0 - 2024-11-04 -------------------------- diff --git a/modules/account_budget/account.py b/modules/account_budget/account.py index ce30f6b29b..904ce5e62d 100644 --- a/modules/account_budget/account.py +++ b/modules/account_budget/account.py @@ -547,7 +547,7 @@ class BudgetLine(BudgetLineMixin, ModelSQL, ModelView): children = cls.__table__() line = Line.__table__() - amount = Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)) + amount = Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)) red_sql = reduce_ids(table.id, [r.id for r in records]) periods = Transaction().context.get('periods') if not periods: @@ -691,7 +691,7 @@ class BudgetLinePeriod(AmountMixin, ModelSQL, ModelView): move = Move.__table__() line = MoveLine.__table__() - amount = Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)) + amount = Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)) red_sql = reduce_ids(table.id, [r.id for r in records]) periods = Transaction().context.get('periods') if not periods: diff --git a/modules/account_budget/tests/scenario_account_budget.rst b/modules/account_budget/tests/scenario_account_budget.rst index 8197f5a913..4b6ed89d0b 100644 --- a/modules/account_budget/tests/scenario_account_budget.rst +++ b/modules/account_budget/tests/scenario_account_budget.rst @@ -56,11 +56,11 @@ Create a budget:: >>> revenue_budget, = BudgetLine.find( ... [('account', '=', accounts['revenue'].id)]) - >>> revenue_budget.amount = Decimal(-150) + >>> revenue_budget.amount = Decimal(150) >>> revenue_budget.save() >>> expense_budget, = BudgetLine.find( ... [('account', '=', accounts['expense'].id)]) - >>> expense_budget.amount = Decimal(50) + >>> expense_budget.amount = Decimal(-50) >>> expense_budget.save() >>> budget.click('update_lines') @@ -103,21 +103,21 @@ Check actual amount of the budget:: >>> pl_budget, = budget.root_lines >>> pl_budget.total_amount - Decimal('-100.00') + Decimal('100.00') >>> pl_budget.actual_amount - Decimal('-70.00') + Decimal('70.00') >>> pl_budget.percentage Decimal('0.7000') >>> revenue_budget.total_amount - Decimal('-150.00') + Decimal('150.00') >>> revenue_budget.actual_amount - Decimal('-130.00') + Decimal('130.00') >>> revenue_budget.percentage Decimal('0.8667') >>> expense_budget.total_amount - Decimal('50.00') + Decimal('-50.00') >>> expense_budget.actual_amount - Decimal('60.00') + Decimal('-60.00') >>> expense_budget.percentage Decimal('1.2000') @@ -129,20 +129,20 @@ Create periods:: >>> len(pl_budget.periods) 12 >>> {p.total_amount for p in pl_budget.periods} - {Decimal('-8.33')} + {Decimal('8.33')} >>> len(revenue_budget.periods) 12 >>> {p.total_amount for p in revenue_budget.periods} - {Decimal('-12.50')} + {Decimal('12.50')} >>> len(expense_budget.periods) 12 >>> {p.total_amount for p in expense_budget.periods} - {Decimal('4.16')} + {Decimal('-4.16')} Check the budget's periods:: >>> pl_budget.periods[0].actual_amount - Decimal('-70.00') + Decimal('70.00') >>> pl_budget.periods[0].percentage Decimal('8.4034') >>> pl_budget.periods[1].actual_amount @@ -150,7 +150,7 @@ Check the budget's periods:: >>> pl_budget.periods[1].percentage Decimal('0.0000') >>> revenue_budget.periods[0].actual_amount - Decimal('-130.00') + Decimal('130.00') >>> revenue_budget.periods[0].percentage Decimal('10.4000') >>> revenue_budget.periods[1].actual_amount @@ -158,7 +158,7 @@ Check the budget's periods:: >>> revenue_budget.periods[1].percentage Decimal('0.0000') >>> expense_budget.periods[0].actual_amount - Decimal('60.00') + Decimal('-60.00') >>> expense_budget.periods[0].percentage Decimal('14.4231') >>> expense_budget.periods[1].actual_amount @@ -190,7 +190,7 @@ Copy the budget without amounts:: 'New Budget' >>> new_pl_budget, = new_budget.root_lines >>> new_pl_budget.total_amount - Decimal('-125.00') + Decimal('125.00') >>> new_pl_budget.actual_amount Decimal('0.00') >>> new_pl_budget.percentage diff --git a/modules/analytic_budget/CHANGELOG b/modules/analytic_budget/CHANGELOG index ff3627c058..b45e3ea790 100644 --- a/modules/analytic_budget/CHANGELOG +++ b/modules/analytic_budget/CHANGELOG @@ -1,3 +1,4 @@ +* Invert sign of budget amount Version 7.4.0 - 2024-11-04 -------------------------- diff --git a/modules/analytic_budget/analytic_account.py b/modules/analytic_budget/analytic_account.py index 2c1c5c6730..d5a839cd02 100644 --- a/modules/analytic_budget/analytic_account.py +++ b/modules/analytic_budget/analytic_account.py @@ -178,7 +178,7 @@ class BudgetLine(BudgetLineMixin, ModelSQL, ModelView): table = cls.__table__() children = cls.__table__() - balance = Sum(Coalesce(line.debit, 0) - Coalesce(line.credit, 0)) + balance = Sum(Coalesce(line.credit, 0) - Coalesce(line.debit, 0)) red_sql = reduce_ids(table.id, [r.id for r in records]) with Transaction().set_context(context): query_where = Line.query_get(line) diff --git a/modules/analytic_budget/tests/scenario_analytic_budget.rst b/modules/analytic_budget/tests/scenario_analytic_budget.rst index 0208a3ed24..02c262fcbc 100644 --- a/modules/analytic_budget/tests/scenario_analytic_budget.rst +++ b/modules/analytic_budget/tests/scenario_analytic_budget.rst @@ -64,12 +64,12 @@ Create a budget:: >>> analytic_budget, = BudgetLine.find( ... [('account', '=', analytic_account.id)]) >>> analytic_budget.sequence = 1 - >>> analytic_budget.amount = Decimal(-70) + >>> analytic_budget.amount = Decimal(70) >>> analytic_budget.save() >>> other_analytic_budget, = BudgetLine.find( ... [('account', '=', other_analytic_account.id)]) >>> other_analytic_budget.sequence = 2 - >>> other_analytic_budget.amount = Decimal(-50) + >>> other_analytic_budget.amount = Decimal(50) >>> other_analytic_budget.save() >>> budget.click('update_lines') @@ -103,15 +103,15 @@ Create moves to test the budget:: Check actual amount the budget:: >>> analytic_budget.total_amount - Decimal('-70.00') + Decimal('70.00') >>> analytic_budget.actual_amount - Decimal('-60.00') + Decimal('60.00') >>> analytic_budget.percentage Decimal('0.8571') >>> other_analytic_budget.total_amount - Decimal('-50.00') + Decimal('50.00') >>> other_analytic_budget.actual_amount - Decimal('-40.00') + Decimal('40.00') >>> other_analytic_budget.percentage Decimal('0.8000') @@ -127,7 +127,7 @@ Copy the budget without amounts:: >>> assertEqual(new_budget.end_date, next_period.end_date) >>> analytic_budget, other_analytic_budget = new_budget.lines >>> analytic_budget.total_amount - Decimal('-84.00') + Decimal('84.00') >>> analytic_budget.actual_amount Decimal('0.00') >>> analytic_budget.percentage