Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added parentheses for correct query formation for logical OR condition #43602

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

ljain112
Copy link
Contributor

Issue:
Due to missing parenthesis, OR condition was executed outside the condition due to which cancelled opening GL Entries were included in the query.
Before:

SELECT 
  `account`, 
  `account_currency`, 
  SUM(`debit_in_account_currency`) `debit_in_account_currency`, 
  SUM(`credit_in_account_currency`) `credit_in_account_currency`, 
  SUM(`debit`) `debit`, 
  SUM(`credit`) `credit`, 
  `cost_center`, 
  `finance_book`, 
  `project`, 
  `account` 
FROM 
  `tabGL Entry` 
WHERE 
  `company` = 'Test' 
  AND `is_cancelled` = 0 
  AND `account` IN (...) 
  AND `posting_date` BETWEEN '2022-04-01' 
  AND '2023-03-31' 
  OR `is_opening` = 'Yes' 
  AND `voucher_type` <> 'Period Closing Voucher' 
GROUP BY 
  `cost_center`, 
  `finance_book`, 
  `project`, 
  `account`

After:

SELECT 
  `account`, 
  `account_currency`, 
  SUM(`debit_in_account_currency`) `debit_in_account_currency`, 
  SUM(`credit_in_account_currency`) `credit_in_account_currency`, 
  SUM(`debit`) `debit`, 
  SUM(`credit`) `credit`, 
  `cost_center`, 
  `finance_book`, 
  `project`, 
  `account` 
FROM 
  `tabGL Entry` 
WHERE 
  `company` = 'Test' 
  AND `is_cancelled` = 0 
  AND `account` IN ( ...) 
  AND (
    `posting_date` BETWEEN '2022-04-01' 
    AND '2023-03-31' 
    OR `is_opening` = 'Yes'
  ) 
  AND `voucher_type` <> 'Period Closing Voucher' 
GROUP BY 
  `cost_center`, 
  `finance_book`, 
  `project`, 
  `account`

Frappe Support Issue: https://support.frappe.io/app/hd-ticket/23051

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Oct 10, 2024
@ljain112 ljain112 force-pushed the fix-closing-balances branch from e4c4f41 to c0da8f1 Compare October 11, 2024 05:37
@ruthra-kumar
Copy link
Member

@ljain112
Also specify which versions to trigger backport for on future Pull Requests.

@ruthra-kumar ruthra-kumar merged commit fc66408 into frappe:develop Oct 15, 2024
13 checks passed
@ruthra-kumar ruthra-kumar self-assigned this Oct 15, 2024
@ruthra-kumar ruthra-kumar removed the request for review from deepeshgarg007 October 15, 2024 11:15
ruthra-kumar added a commit that referenced this pull request Oct 15, 2024
…-43602

fix: added parentheses for correct query formation for logical OR condition (backport #43602)
ruthra-kumar added a commit that referenced this pull request Oct 15, 2024
…-43602

fix: added parentheses for correct query formation for logical OR condition (backport #43602)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14 backport version-15-hotfix needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants