fix: set customer and supplier details using sql (#21846)
* fix: set customer and supplier details using sql instead of slowing down the query with get_doc and save() we can just use sql to update the required values for customer and supplier Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * chore: remove extra quote Co-authored-by: Himanshu <himanshuwarekar@yahoo.com> * fix: update sql query to include tabPrice List Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> Co-authored-by: Himanshu <himanshuwarekar@yahoo.com>
This commit is contained in:
parent
dd3e52184c
commit
baef43977b
@ -1,15 +1,29 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
invalid_selling_item_price = frappe.db.sql(
|
"""
|
||||||
"""SELECT name FROM `tabItem Price` WHERE selling = 1 and buying = 0 and (supplier IS NOT NULL or supplier = '')"""
|
set proper customer and supplier details for item price
|
||||||
)
|
based on selling and buying values
|
||||||
invalid_buying_item_price = frappe.db.sql(
|
"""
|
||||||
"""SELECT name FROM `tabItem Price` WHERE selling = 0 and buying = 1 and (customer IS NOT NULL or customer = '')"""
|
|
||||||
)
|
# update for selling
|
||||||
docs_to_modify = invalid_buying_item_price + invalid_selling_item_price
|
frappe.db.sql(
|
||||||
for d in docs_to_modify:
|
"""UPDATE `tabItem Price` ip, `tabPrice List` pl
|
||||||
# saving the doc will auto reset invalid customer/supplier field
|
SET ip.`reference` = ip.`customer`, ip.`supplier` = NULL
|
||||||
doc = frappe.get_doc("Item Price", d[0])
|
WHERE ip.`selling` = 1
|
||||||
doc.save()
|
AND ip.`buying` = 0
|
||||||
|
AND (ip.`supplier` IS NOT NULL OR ip.`supplier` = '')
|
||||||
|
AND ip.`price_list` = pl.`name`
|
||||||
|
AND pl.`enabled` = 1""")
|
||||||
|
|
||||||
|
# update for buying
|
||||||
|
frappe.db.sql(
|
||||||
|
"""UPDATE `tabItem Price` ip, `tabPrice List` pl
|
||||||
|
SET ip.`reference` = ip.`supplier`, ip.`customer` = NULL
|
||||||
|
WHERE ip.`selling` = 0
|
||||||
|
AND ip.`buying` = 1
|
||||||
|
AND (ip.`customer` IS NOT NULL OR ip.`customer` = '')
|
||||||
|
AND ip.`price_list` = pl.`name`
|
||||||
|
AND pl.`enabled` = 1""")
|
||||||
|
Loading…
Reference in New Issue
Block a user