mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-31 23:33:43 +00:00
Merge pull request #56062 from mihir-kandoi/pg-accounts-pos
refactor(postgres): port Accounts POS, pricing & invoicing doctype queries to the query builder
This commit is contained in:
@@ -84,10 +84,10 @@ class CostCenter(NestedSet):
|
|||||||
return frappe.db.get_value("GL Entry", {"cost_center": self.name})
|
return frappe.db.get_value("GL Entry", {"cost_center": self.name})
|
||||||
|
|
||||||
def check_if_child_exists(self):
|
def check_if_child_exists(self):
|
||||||
return frappe.db.sql(
|
return frappe.get_all(
|
||||||
"select name from `tabCost Center` where \
|
"Cost Center",
|
||||||
parent_cost_center = %s and docstatus != 2",
|
filters={"parent_cost_center": self.name, "docstatus": ["!=", 2]},
|
||||||
self.name,
|
pluck="name",
|
||||||
)
|
)
|
||||||
|
|
||||||
def if_allocation_exists_against_cost_center(self):
|
def if_allocation_exists_against_cost_center(self):
|
||||||
|
|||||||
@@ -72,10 +72,8 @@ class FiscalYear(Document):
|
|||||||
|
|
||||||
if existing_fiscal_years:
|
if existing_fiscal_years:
|
||||||
for existing in existing_fiscal_years:
|
for existing in existing_fiscal_years:
|
||||||
company_for_existing = frappe.db.sql_list(
|
company_for_existing = frappe.get_all(
|
||||||
"""select company from `tabFiscal Year Company`
|
"Fiscal Year Company", filters={"parent": existing.name}, pluck="company"
|
||||||
where parent=%s""",
|
|
||||||
existing.name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
overlap = False
|
overlap = False
|
||||||
|
|||||||
@@ -39,28 +39,32 @@ def get_loyalty_point_entries(customer, loyalty_program, company, expiry_date=No
|
|||||||
if not expiry_date:
|
if not expiry_date:
|
||||||
expiry_date = today()
|
expiry_date = today()
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.get_all(
|
||||||
"""
|
"Loyalty Point Entry",
|
||||||
select name, loyalty_points, expiry_date, loyalty_program_tier, invoice_type, invoice
|
filters={
|
||||||
from `tabLoyalty Point Entry`
|
"customer": customer,
|
||||||
where customer=%s and loyalty_program=%s
|
"loyalty_program": loyalty_program,
|
||||||
and expiry_date>=%s and loyalty_points>0 and company=%s
|
"expiry_date": [">=", expiry_date],
|
||||||
order by expiry_date
|
"loyalty_points": [">", 0],
|
||||||
""",
|
"company": company,
|
||||||
(customer, loyalty_program, expiry_date, company),
|
},
|
||||||
as_dict=1,
|
fields=["name", "loyalty_points", "expiry_date", "loyalty_program_tier", "invoice_type", "invoice"],
|
||||||
|
order_by="expiry_date",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_redemption_details(customer, loyalty_program, company):
|
def get_redemption_details(customer, loyalty_program, company):
|
||||||
return frappe._dict(
|
return frappe._dict(
|
||||||
frappe.db.sql(
|
frappe.get_all(
|
||||||
"""
|
"Loyalty Point Entry",
|
||||||
select redeem_against, sum(loyalty_points)
|
filters={
|
||||||
from `tabLoyalty Point Entry`
|
"customer": customer,
|
||||||
where customer=%s and loyalty_program=%s and loyalty_points<0 and company=%s
|
"loyalty_program": loyalty_program,
|
||||||
group by redeem_against
|
"loyalty_points": ["<", 0],
|
||||||
""",
|
"company": company,
|
||||||
(customer, loyalty_program, company),
|
},
|
||||||
|
fields=["redeem_against", {"SUM": "loyalty_points", "as": "loyalty_points"}],
|
||||||
|
group_by="redeem_against",
|
||||||
|
as_list=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -505,19 +505,16 @@ class POSInvoice(SalesInvoice):
|
|||||||
if d.get("serial_no"):
|
if d.get("serial_no"):
|
||||||
serial_nos = get_serial_nos(d.serial_no)
|
serial_nos = get_serial_nos(d.serial_no)
|
||||||
for sr in serial_nos:
|
for sr in serial_nos:
|
||||||
serial_no_exists = frappe.db.sql(
|
serial_no_exists = frappe.get_all(
|
||||||
"""
|
"POS Invoice Item",
|
||||||
SELECT name
|
filters={"parent": self.return_against},
|
||||||
FROM `tabPOS Invoice Item`
|
or_filters=[
|
||||||
WHERE
|
["serial_no", "=", sr],
|
||||||
parent = %s
|
["serial_no", "like", f"{sr}\n%"],
|
||||||
and (serial_no = %s
|
["serial_no", "like", f"%\n{sr}"],
|
||||||
or serial_no like %s
|
["serial_no", "like", f"%\n{sr}\n%"],
|
||||||
or serial_no like %s
|
],
|
||||||
or serial_no like %s
|
limit=1,
|
||||||
)
|
|
||||||
""",
|
|
||||||
(self.return_against, sr, sr + "\n%", "%\n" + sr, "%\n" + sr + "\n%"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not serial_no_exists:
|
if not serial_no_exists:
|
||||||
@@ -963,15 +960,9 @@ def get_bundle_availability(bundle_item_code, warehouse):
|
|||||||
|
|
||||||
|
|
||||||
def get_bin_qty(item_code, warehouse):
|
def get_bin_qty(item_code, warehouse):
|
||||||
bin_qty = frappe.db.sql(
|
actual_qty = frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, "actual_qty")
|
||||||
"""select actual_qty from `tabBin`
|
|
||||||
where item_code = %s and warehouse = %s
|
|
||||||
limit 1""",
|
|
||||||
(item_code, warehouse),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
return bin_qty[0].actual_qty or 0 if bin_qty else 0
|
return actual_qty or 0
|
||||||
|
|
||||||
|
|
||||||
def get_pos_reserved_qty(item_code, warehouse):
|
def get_pos_reserved_qty(item_code, warehouse):
|
||||||
|
|||||||
@@ -118,14 +118,21 @@ class POSProfile(Document):
|
|||||||
|
|
||||||
def validate_default_profile(self):
|
def validate_default_profile(self):
|
||||||
for row in self.applicable_for_users:
|
for row in self.applicable_for_users:
|
||||||
res = frappe.db.sql(
|
pfu = frappe.qb.DocType("POS Profile User")
|
||||||
"""select pf.name
|
pf = frappe.qb.DocType("POS Profile")
|
||||||
from
|
res = (
|
||||||
`tabPOS Profile User` pfu, `tabPOS Profile` pf
|
frappe.qb.from_(pfu)
|
||||||
where
|
.inner_join(pf)
|
||||||
pf.name = pfu.parent and pfu.user = %s and pf.name != %s and pf.company = %s
|
.on(pf.name == pfu.parent)
|
||||||
and pfu.default=1 and pf.disabled = 0""",
|
.select(pf.name)
|
||||||
(row.user, self.name, self.company),
|
.where(
|
||||||
|
(pfu.user == row.user)
|
||||||
|
& (pf.name != self.name)
|
||||||
|
& (pf.company == self.company)
|
||||||
|
& (pfu.default == 1)
|
||||||
|
& (pf.disabled == 0)
|
||||||
|
)
|
||||||
|
.run()
|
||||||
)
|
)
|
||||||
|
|
||||||
if row.default and res:
|
if row.default and res:
|
||||||
@@ -265,10 +272,11 @@ def get_permitted_nodes(group_type):
|
|||||||
|
|
||||||
def get_child_nodes(group_type, root):
|
def get_child_nodes(group_type, root):
|
||||||
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
||||||
return frappe.db.sql(
|
return frappe.get_all(
|
||||||
f""" Select name, lft, rgt from `tab{group_type}` where
|
group_type,
|
||||||
lft >= {lft} and rgt <= {rgt} order by lft""",
|
filters={"lft": [">=", lft], "rgt": ["<=", rgt]},
|
||||||
as_dict=1,
|
fields=["name", "lft", "rgt"],
|
||||||
|
order_by="lft",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -278,40 +286,33 @@ def pos_profile_query(doctype: str, txt: str, searchfield: str, start: int, page
|
|||||||
user = frappe.session["user"]
|
user = frappe.session["user"]
|
||||||
company = filters.get("company") or frappe.defaults.get_user_default("company")
|
company = filters.get("company") or frappe.defaults.get_user_default("company")
|
||||||
|
|
||||||
args = {
|
pf = frappe.qb.DocType("POS Profile")
|
||||||
"user": user,
|
pfu = frappe.qb.DocType("POS Profile User")
|
||||||
"start": start,
|
|
||||||
"company": company,
|
|
||||||
"page_len": page_len,
|
|
||||||
"txt": "%%%s%%" % txt,
|
|
||||||
}
|
|
||||||
|
|
||||||
pos_profile = frappe.db.sql(
|
pos_profile = (
|
||||||
"""select pf.name
|
frappe.qb.from_(pf)
|
||||||
from
|
.inner_join(pfu)
|
||||||
`tabPOS Profile` pf, `tabPOS Profile User` pfu
|
.on(pfu.parent == pf.name)
|
||||||
where
|
.select(pf.name)
|
||||||
pfu.parent = pf.name and pfu.user = %(user)s and pf.company = %(company)s
|
.where((pfu.user == user) & (pf.company == company) & pf.name.like(f"%{txt}%") & (pf.disabled == 0))
|
||||||
and (pf.name like %(txt)s)
|
.limit(page_len)
|
||||||
and pf.disabled = 0 limit %(page_len)s offset %(start)s""",
|
.offset(start)
|
||||||
args,
|
.run()
|
||||||
)
|
)
|
||||||
|
|
||||||
if not pos_profile:
|
if not pos_profile:
|
||||||
del args["user"]
|
pos_profile = (
|
||||||
|
frappe.qb.from_(pf)
|
||||||
pos_profile = frappe.db.sql(
|
.left_join(pfu)
|
||||||
"""select pf.name
|
.on(pf.name == pfu.parent)
|
||||||
from
|
.select(pf.name)
|
||||||
`tabPOS Profile` pf left join `tabPOS Profile User` pfu
|
.where(
|
||||||
on
|
(pfu.user.isnull() | (pfu.user == ""))
|
||||||
pf.name = pfu.parent
|
& (pf.company == company)
|
||||||
where
|
& pf.name.like(f"%{txt}%")
|
||||||
ifnull(pfu.user, '') = ''
|
& (pf.disabled == 0)
|
||||||
and pf.company = %(company)s
|
)
|
||||||
and pf.name like %(txt)s
|
.run()
|
||||||
and pf.disabled = 0""",
|
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return pos_profile
|
return pos_profile
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ def _get_pricing_rules(apply_on, args, values):
|
|||||||
if apply_on_field == "item_code":
|
if apply_on_field == "item_code":
|
||||||
if args.get("uom", None):
|
if args.get("uom", None):
|
||||||
item_conditions += (
|
item_conditions += (
|
||||||
" and ({child_doc}.uom={item_uom} or IFNULL({child_doc}.uom, '')='')".format(
|
" and ({child_doc}.uom={item_uom} or COALESCE({child_doc}.uom, '')='')".format(
|
||||||
child_doc=child_doc, item_uom=frappe.db.escape(args.get("uom"))
|
child_doc=child_doc, item_uom=frappe.db.escape(args.get("uom"))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -127,7 +127,7 @@ def _get_pricing_rules(apply_on, args, values):
|
|||||||
elif apply_on_field == "item_group":
|
elif apply_on_field == "item_group":
|
||||||
item_conditions = _get_tree_conditions(args, "Item Group", child_doc, False)
|
item_conditions = _get_tree_conditions(args, "Item Group", child_doc, False)
|
||||||
if args.get("uom", None):
|
if args.get("uom", None):
|
||||||
item_conditions += " and ({child_doc}.uom={item_uom} or IFNULL({child_doc}.uom, '')='')".format(
|
item_conditions += " and ({child_doc}.uom={item_uom} or COALESCE({child_doc}.uom, '')='')".format(
|
||||||
child_doc=child_doc, item_uom=frappe.db.escape(args.get("uom"))
|
child_doc=child_doc, item_uom=frappe.db.escape(args.get("uom"))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ def _get_pricing_rules(apply_on, args, values):
|
|||||||
if not args.price_list:
|
if not args.price_list:
|
||||||
args.price_list = None
|
args.price_list = None
|
||||||
|
|
||||||
conditions += " and ifnull(`tabPricing Rule`.for_price_list, '') in (%(price_list)s, '')"
|
conditions += " and coalesce(`tabPricing Rule`.for_price_list, '') in (%(price_list)s, '')"
|
||||||
values["price_list"] = args.get("price_list")
|
values["price_list"] = args.get("price_list")
|
||||||
|
|
||||||
pricing_rules = (
|
pricing_rules = (
|
||||||
@@ -195,10 +195,8 @@ def _get_tree_conditions(args, parenttype, table, allow_blank=True):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
frappe.throw(_("Invalid {0}").format(args.get(field)))
|
frappe.throw(_("Invalid {0}").format(args.get(field)))
|
||||||
|
|
||||||
parent_groups = frappe.db.sql_list(
|
parent_groups = frappe.get_all(
|
||||||
"""select name from `tab{}`
|
parenttype, filters={"lft": ["<=", lft], "rgt": [">=", rgt]}, pluck="name"
|
||||||
where lft<={} and rgt>={}""".format(parenttype, "%s", "%s"),
|
|
||||||
(lft, rgt),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if parenttype in ["Customer Group", "Item Group", "Territory"]:
|
if parenttype in ["Customer Group", "Item Group", "Territory"]:
|
||||||
@@ -217,14 +215,14 @@ def _get_tree_conditions(args, parenttype, table, allow_blank=True):
|
|||||||
if parent_groups:
|
if parent_groups:
|
||||||
if allow_blank:
|
if allow_blank:
|
||||||
parent_groups.append("")
|
parent_groups.append("")
|
||||||
condition = "ifnull({table}.{field}, '') in ({parent_groups})".format(
|
condition = "coalesce({table}.{field}, '') in ({parent_groups})".format(
|
||||||
table=table, field=field, parent_groups=", ".join(frappe.db.escape(d) for d in parent_groups)
|
table=table, field=field, parent_groups=", ".join(frappe.db.escape(d) for d in parent_groups)
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.flags.tree_conditions[key] = condition
|
frappe.flags.tree_conditions[key] = condition
|
||||||
|
|
||||||
elif allow_blank:
|
elif allow_blank:
|
||||||
condition = f"ifnull({table}.{field}, '') = ''"
|
condition = f"coalesce({table}.{field}, '') = ''"
|
||||||
|
|
||||||
return condition
|
return condition
|
||||||
|
|
||||||
@@ -232,10 +230,10 @@ def _get_tree_conditions(args, parenttype, table, allow_blank=True):
|
|||||||
def get_other_conditions(conditions, values, args):
|
def get_other_conditions(conditions, values, args):
|
||||||
for field in ["company", "customer", "supplier", "campaign", "sales_partner"]:
|
for field in ["company", "customer", "supplier", "campaign", "sales_partner"]:
|
||||||
if args.get(field):
|
if args.get(field):
|
||||||
conditions += f" and ifnull(`tabPricing Rule`.{field}, '') in (%({field})s, '')"
|
conditions += f" and coalesce(`tabPricing Rule`.{field}, '') in (%({field})s, '')"
|
||||||
values[field] = args.get(field)
|
values[field] = args.get(field)
|
||||||
else:
|
else:
|
||||||
conditions += f" and ifnull(`tabPricing Rule`.{field}, '') = ''"
|
conditions += f" and coalesce(`tabPricing Rule`.{field}, '') = ''"
|
||||||
|
|
||||||
for parenttype in ["Customer Group", "Territory", "Supplier Group"]:
|
for parenttype in ["Customer Group", "Territory", "Supplier Group"]:
|
||||||
group_condition = _get_tree_conditions(args, parenttype, "`tabPricing Rule`")
|
group_condition = _get_tree_conditions(args, parenttype, "`tabPricing Rule`")
|
||||||
@@ -248,8 +246,8 @@ def get_other_conditions(conditions, values, args):
|
|||||||
or frappe.get_value(args.get("doctype"), args.get("name"), "posting_date", ignore=True)
|
or frappe.get_value(args.get("doctype"), args.get("name"), "posting_date", ignore=True)
|
||||||
)
|
)
|
||||||
if date:
|
if date:
|
||||||
conditions += """ and %(transaction_date)s between ifnull(`tabPricing Rule`.valid_from, '2000-01-01')
|
conditions += """ and %(transaction_date)s between coalesce(`tabPricing Rule`.valid_from, '2000-01-01')
|
||||||
and ifnull(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
and coalesce(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
||||||
values["transaction_date"] = date
|
values["transaction_date"] = date
|
||||||
|
|
||||||
if args.get("doctype") in [
|
if args.get("doctype") in [
|
||||||
@@ -264,9 +262,9 @@ def get_other_conditions(conditions, values, args):
|
|||||||
"POS Invoice",
|
"POS Invoice",
|
||||||
"POS Invoice Item",
|
"POS Invoice Item",
|
||||||
]:
|
]:
|
||||||
conditions += """ and ifnull(`tabPricing Rule`.selling, 0) = 1"""
|
conditions += """ and coalesce(`tabPricing Rule`.selling, 0) = 1"""
|
||||||
else:
|
else:
|
||||||
conditions += """ and ifnull(`tabPricing Rule`.buying, 0) = 1"""
|
conditions += """ and coalesce(`tabPricing Rule`.buying, 0) = 1"""
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|||||||
@@ -524,16 +524,11 @@ class PurchaseInvoice(BuyingController):
|
|||||||
def check_prev_docstatus(self):
|
def check_prev_docstatus(self):
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if d.purchase_order:
|
if d.purchase_order:
|
||||||
submitted = frappe.db.sql(
|
submitted = frappe.db.exists("Purchase Order", {"docstatus": 1, "name": d.purchase_order})
|
||||||
"select name from `tabPurchase Order` where docstatus = 1 and name = %s", d.purchase_order
|
|
||||||
)
|
|
||||||
if not submitted:
|
if not submitted:
|
||||||
frappe.throw(_("Purchase Order {0} is not submitted").format(d.purchase_order))
|
frappe.throw(_("Purchase Order {0} is not submitted").format(d.purchase_order))
|
||||||
if d.purchase_receipt:
|
if d.purchase_receipt:
|
||||||
submitted = frappe.db.sql(
|
submitted = frappe.db.exists("Purchase Receipt", {"docstatus": 1, "name": d.purchase_receipt})
|
||||||
"select name from `tabPurchase Receipt` where docstatus = 1 and name = %s",
|
|
||||||
d.purchase_receipt,
|
|
||||||
)
|
|
||||||
if not submitted:
|
if not submitted:
|
||||||
frappe.throw(_("Purchase Receipt {0} is not submitted").format(d.purchase_receipt))
|
frappe.throw(_("Purchase Receipt {0} is not submitted").format(d.purchase_receipt))
|
||||||
|
|
||||||
@@ -801,25 +796,20 @@ class PurchaseInvoice(BuyingController):
|
|||||||
if cint(frappe.get_single_value("Accounts Settings", "check_supplier_invoice_uniqueness")):
|
if cint(frappe.get_single_value("Accounts Settings", "check_supplier_invoice_uniqueness")):
|
||||||
fiscal_year = get_fiscal_year(self.posting_date, company=self.company, as_dict=True)
|
fiscal_year = get_fiscal_year(self.posting_date, company=self.company, as_dict=True)
|
||||||
|
|
||||||
pi = frappe.db.sql(
|
pi = frappe.get_all(
|
||||||
"""select name from `tabPurchase Invoice`
|
"Purchase Invoice",
|
||||||
where
|
filters={
|
||||||
bill_no = %(bill_no)s
|
|
||||||
and supplier = %(supplier)s
|
|
||||||
and name != %(name)s
|
|
||||||
and docstatus < 2
|
|
||||||
and posting_date between %(year_start_date)s and %(year_end_date)s""",
|
|
||||||
{
|
|
||||||
"bill_no": self.bill_no,
|
"bill_no": self.bill_no,
|
||||||
"supplier": self.supplier,
|
"supplier": self.supplier,
|
||||||
"name": self.name,
|
"name": ["!=", self.name],
|
||||||
"year_start_date": fiscal_year.year_start_date,
|
"docstatus": ["<", 2],
|
||||||
"year_end_date": fiscal_year.year_end_date,
|
"posting_date": ["between", [fiscal_year.year_start_date, fiscal_year.year_end_date]],
|
||||||
},
|
},
|
||||||
|
pluck="name",
|
||||||
)
|
)
|
||||||
|
|
||||||
if pi:
|
if pi:
|
||||||
pi = pi[0][0]
|
pi = pi[0]
|
||||||
|
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("Supplier Invoice No exists in Purchase Invoice {0}").format(
|
_("Supplier Invoice No exists in Purchase Invoice {0}").format(
|
||||||
|
|||||||
@@ -55,10 +55,13 @@ class ExpenseAccountService:
|
|||||||
else:
|
else:
|
||||||
# check if 'Stock Received But Not Billed' account is credited in Purchase receipt or not
|
# check if 'Stock Received But Not Billed' account is credited in Purchase receipt or not
|
||||||
if item.purchase_receipt:
|
if item.purchase_receipt:
|
||||||
negative_expense_booked_in_pr = frappe.db.sql(
|
negative_expense_booked_in_pr = frappe.db.exists(
|
||||||
"""select name from `tabGL Entry`
|
"GL Entry",
|
||||||
where voucher_type='Purchase Receipt' and voucher_no=%s and account = %s""",
|
{
|
||||||
(item.purchase_receipt, stock_not_billed_account),
|
"voucher_type": "Purchase Receipt",
|
||||||
|
"voucher_no": item.purchase_receipt,
|
||||||
|
"account": stock_not_billed_account,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if negative_expense_booked_in_pr:
|
if negative_expense_booked_in_pr:
|
||||||
|
|||||||
@@ -395,10 +395,14 @@ class PurchaseInvoiceGLComposer(BaseGLComposer):
|
|||||||
):
|
):
|
||||||
# Post reverse entry for Stock-Received-But-Not-Billed if booked in Purchase Receipt
|
# Post reverse entry for Stock-Received-But-Not-Billed if booked in Purchase Receipt
|
||||||
if item.purchase_receipt and valuation_tax_accounts:
|
if item.purchase_receipt and valuation_tax_accounts:
|
||||||
negative_expense_booked_in_pr = frappe.db.sql(
|
negative_expense_booked_in_pr = frappe.get_all(
|
||||||
"""select name from `tabGL Entry`
|
"GL Entry",
|
||||||
where voucher_type='Purchase Receipt' and voucher_no=%s and account in %s""",
|
filters={
|
||||||
(item.purchase_receipt, valuation_tax_accounts),
|
"voucher_type": "Purchase Receipt",
|
||||||
|
"voucher_no": item.purchase_receipt,
|
||||||
|
"account": ["in", valuation_tax_accounts],
|
||||||
|
},
|
||||||
|
pluck="name",
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -56,11 +56,14 @@ def valdiate_taxes_and_charges_template(doc):
|
|||||||
# doc.is_default = 1
|
# doc.is_default = 1
|
||||||
|
|
||||||
if doc.is_default == 1:
|
if doc.is_default == 1:
|
||||||
frappe.db.sql(
|
template = frappe.qb.DocType(doc.doctype)
|
||||||
f"""update `tab{doc.doctype}` set is_default = 0
|
(
|
||||||
where is_default = 1 and name != %s and company = %s""",
|
frappe.qb.update(template)
|
||||||
(doc.name, doc.company),
|
.set(template.is_default, 0)
|
||||||
)
|
.where(
|
||||||
|
(template.is_default == 1) & (template.name != doc.name) & (template.company == doc.company)
|
||||||
|
)
|
||||||
|
).run()
|
||||||
|
|
||||||
validate_disabled(doc)
|
validate_disabled(doc)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user