mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
refactor: pass dimension filters to query
(cherry picked from commit ff60ec85b8)
# Conflicts:
# erpnext/controllers/accounts_controller.py
This commit is contained in:
@@ -113,6 +113,15 @@ class PaymentReconciliation(Document):
|
|||||||
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
|
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
|
||||||
condition = self.get_conditions(get_payments=True)
|
condition = self.get_conditions(get_payments=True)
|
||||||
|
|
||||||
|
# pass dynamic dimension filter values to query builder
|
||||||
|
dimensions = {}
|
||||||
|
dimensions_and_defaults = get_dimensions()
|
||||||
|
for x in dimensions_and_defaults[0]:
|
||||||
|
dimension = x.fieldname
|
||||||
|
if self.get(dimension):
|
||||||
|
dimensions.update({dimension: self.get(dimension)})
|
||||||
|
condition.update({"accounting_dimensions": dimensions})
|
||||||
|
|
||||||
payment_entries = get_advance_payment_entries_for_regional(
|
payment_entries = get_advance_payment_entries_for_regional(
|
||||||
self.party_type,
|
self.party_type,
|
||||||
self.party,
|
self.party,
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, bold, qb, throw
|
from frappe import _, bold, qb, throw
|
||||||
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
from frappe.query_builder import Criterion
|
||||||
|
from frappe.query_builder.custom import ConstantColumn
|
||||||
|
>>>>>>> ff60ec85b8 (refactor: pass dimension filters to query)
|
||||||
from frappe.query_builder.functions import Abs, Sum
|
from frappe.query_builder.functions import Abs, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
@@ -2542,6 +2547,7 @@ def get_advance_payment_entries(
|
|||||||
payment_entries_against_order, unallocated_payment_entries = [], []
|
payment_entries_against_order, unallocated_payment_entries = [], []
|
||||||
limit_cond = "limit %s" % limit if limit else ""
|
limit_cond = "limit %s" % limit if limit else ""
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if order_list or against_all_orders:
|
if order_list or against_all_orders:
|
||||||
if order_list:
|
if order_list:
|
||||||
reference_condition = " and t2.reference_name in ({0})".format(
|
reference_condition = " and t2.reference_name in ({0})".format(
|
||||||
@@ -2550,6 +2556,45 @@ def get_advance_payment_entries(
|
|||||||
else:
|
else:
|
||||||
reference_condition = ""
|
reference_condition = ""
|
||||||
order_list = []
|
order_list = []
|
||||||
|
=======
|
||||||
|
if payment_type == "Receive":
|
||||||
|
q = q.select((payment_entry.source_exchange_rate).as_("exchange_rate"))
|
||||||
|
else:
|
||||||
|
q = q.select((payment_entry.target_exchange_rate).as_("exchange_rate"))
|
||||||
|
|
||||||
|
if condition:
|
||||||
|
# conditions should be built as an array and passed as Criterion
|
||||||
|
common_filter_conditions = []
|
||||||
|
|
||||||
|
common_filter_conditions.append(payment_entry.company == condition["company"])
|
||||||
|
if condition.get("name", None):
|
||||||
|
common_filter_conditions.append(payment_entry.name.like(f"%{condition.get('name')}%"))
|
||||||
|
|
||||||
|
if condition.get("from_payment_date"):
|
||||||
|
common_filter_conditions.append(payment_entry.posting_date.gte(condition["from_payment_date"]))
|
||||||
|
|
||||||
|
if condition.get("to_payment_date"):
|
||||||
|
common_filter_conditions.append(payment_entry.posting_date.lte(condition["to_payment_date"]))
|
||||||
|
|
||||||
|
if condition.get("get_payments") == True:
|
||||||
|
if condition.get("cost_center"):
|
||||||
|
common_filter_conditions.append(payment_entry.cost_center == condition["cost_center"])
|
||||||
|
|
||||||
|
if condition.get("accounting_dimensions"):
|
||||||
|
for field, val in condition.get("accounting_dimensions").items():
|
||||||
|
common_filter_conditions.append(payment_entry[field] == val)
|
||||||
|
|
||||||
|
if condition.get("minimum_payment_amount"):
|
||||||
|
common_filter_conditions.append(
|
||||||
|
payment_entry.unallocated_amount.gte(condition["minimum_payment_amount"])
|
||||||
|
)
|
||||||
|
|
||||||
|
if condition.get("maximum_payment_amount"):
|
||||||
|
common_filter_conditions.append(
|
||||||
|
payment_entry.unallocated_amount.lte(condition["maximum_payment_amount"])
|
||||||
|
)
|
||||||
|
q = q.where(Criterion.all(common_filter_conditions))
|
||||||
|
>>>>>>> ff60ec85b8 (refactor: pass dimension filters to query)
|
||||||
|
|
||||||
payment_name_filter = ""
|
payment_name_filter = ""
|
||||||
if payment_name:
|
if payment_name:
|
||||||
|
|||||||
Reference in New Issue
Block a user