mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-16 10:20:31 +00:00
Merge pull request #56215 from mihir-kandoi/pg-controllers-budget-subcon
fix(controllers): budget GROUP BY + subcontracting bool-OR Postgres validity
This commit is contained in:
@@ -3,7 +3,7 @@ from collections import OrderedDict
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, qb
|
from frappe import _, qb
|
||||||
from frappe.query_builder import Criterion
|
from frappe.query_builder import Criterion
|
||||||
from frappe.query_builder.functions import IfNull, Sum
|
from frappe.query_builder.functions import IfNull, Max, Sum
|
||||||
from frappe.utils import fmt_money
|
from frappe.utils import fmt_money
|
||||||
|
|
||||||
from erpnext.accounts.doctype.budget.budget import BudgetError, get_accumulated_monthly_budget
|
from erpnext.accounts.doctype.budget.budget import BudgetError, get_accumulated_monthly_budget
|
||||||
@@ -260,7 +260,11 @@ class BudgetValidation:
|
|||||||
qb.from_(mr)
|
qb.from_(mr)
|
||||||
.inner_join(mri)
|
.inner_join(mri)
|
||||||
.on(mr.name == mri.parent)
|
.on(mr.name == mri.parent)
|
||||||
.select((Sum(IfNull(mri.stock_qty, 0) - IfNull(mri.ordered_qty, 0)) * mri.rate).as_("amount"))
|
# rate is outside the Sum (no GROUP BY -> implicit aggregate); Max() keeps it valid on
|
||||||
|
# postgres and matches MySQL's arbitrary single-rate choice for this aggregate.
|
||||||
|
.select(
|
||||||
|
(Sum(IfNull(mri.stock_qty, 0) - IfNull(mri.ordered_qty, 0)) * Max(mri.rate)).as_("amount")
|
||||||
|
)
|
||||||
.where(Criterion.all(conditions))
|
.where(Criterion.all(conditions))
|
||||||
.run(as_dict=True)
|
.run(as_dict=True)
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -509,8 +509,9 @@ class SubcontractingInwardController:
|
|||||||
(
|
(
|
||||||
Case()
|
Case()
|
||||||
.when(
|
.when(
|
||||||
|
# bool() so the literal renders as true/false; postgres rejects `OR <integer>`
|
||||||
(table.produced_qty < table.qty)
|
(table.produced_qty < table.qty)
|
||||||
| ValueWrapper(allow_delivery_of_overproduced_qty),
|
| ValueWrapper(bool(allow_delivery_of_overproduced_qty)),
|
||||||
table.produced_qty,
|
table.produced_qty,
|
||||||
)
|
)
|
||||||
.else_(table.qty)
|
.else_(table.qty)
|
||||||
|
|||||||
Reference in New Issue
Block a user