Invert sign of budget amount
As budget is based on income statement, the amount must be credit - debit. Closes #13764
This commit is contained in:
@@ -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
|
||||
---
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Invert sign of budget amount
|
||||
|
||||
Version 7.4.0 - 2024-11-04
|
||||
--------------------------
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Invert sign of budget amount
|
||||
|
||||
Version 7.4.0 - 2024-11-04
|
||||
--------------------------
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user