fix: Unlink PO on cancelling SO
This commit is contained in:
parent
4f7af79c31
commit
8396f24e70
@ -19,7 +19,8 @@ from frappe.utils import (
|
|||||||
get_link_to_form,
|
get_link_to_form,
|
||||||
getdate,
|
getdate,
|
||||||
nowdate,
|
nowdate,
|
||||||
today,
|
now,
|
||||||
|
today
|
||||||
)
|
)
|
||||||
from six import text_type
|
from six import text_type
|
||||||
|
|
||||||
@ -811,6 +812,52 @@ class AccountsController(TransactionBase):
|
|||||||
if frappe.db.get_single_value('Accounts Settings', 'unlink_advance_payment_on_cancelation_of_order'):
|
if frappe.db.get_single_value('Accounts Settings', 'unlink_advance_payment_on_cancelation_of_order'):
|
||||||
unlink_ref_doc_from_payment_entries(self)
|
unlink_ref_doc_from_payment_entries(self)
|
||||||
|
|
||||||
|
if self.doctype == "Sales Order":
|
||||||
|
self.unlink_ref_doc_from_po()
|
||||||
|
|
||||||
|
def unlink_ref_doc_from_po(self):
|
||||||
|
print("\n"*5, "*"*50, "\n"*5)
|
||||||
|
|
||||||
|
so_items = []
|
||||||
|
for item in self.items:
|
||||||
|
so_items.append(item.name)
|
||||||
|
|
||||||
|
print("SO Items: ", so_items)
|
||||||
|
|
||||||
|
linked_po = frappe.get_all(
|
||||||
|
'Purchase Order Item',
|
||||||
|
filters = {
|
||||||
|
'sales_order': self.name,
|
||||||
|
'sales_order_item': ['in', so_items],
|
||||||
|
'docstatus': ['<', 2]
|
||||||
|
},
|
||||||
|
pluck='parent'
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Before unlinking: ", linked_po)
|
||||||
|
|
||||||
|
if linked_po:
|
||||||
|
frappe.db.sql("""update `tabPurchase Order Item`
|
||||||
|
set sales_order = null, sales_order_item = null,
|
||||||
|
modified = %s, modified_by = %s
|
||||||
|
where sales_order = %s and sales_order_item in %s
|
||||||
|
and docstatus < 2""", (now(), frappe.session.user, self.name, so_items))
|
||||||
|
|
||||||
|
frappe.msgprint(_("Purchase Orders {0} are un-linked").format("\n".join(linked_po)))
|
||||||
|
|
||||||
|
linked_po = frappe.get_all(
|
||||||
|
'Purchase Order Item',
|
||||||
|
filters = {
|
||||||
|
'sales_order': self.name,
|
||||||
|
'sales_order_item': ['in', so_items],
|
||||||
|
'docstatus': ['<', 2]
|
||||||
|
},
|
||||||
|
pluck='parent'
|
||||||
|
)
|
||||||
|
print("After unlinking: ", linked_po)
|
||||||
|
|
||||||
|
print("\n"*5, "*"*50, "\n"*5)
|
||||||
|
|
||||||
def get_tax_map(self):
|
def get_tax_map(self):
|
||||||
tax_map = {}
|
tax_map = {}
|
||||||
for tax in self.get('taxes'):
|
for tax in self.get('taxes'):
|
||||||
|
@ -209,6 +209,12 @@ class SalesOrder(SellingController):
|
|||||||
from erpnext.accounts.doctype.pricing_rule.utils import update_coupon_code_count
|
from erpnext.accounts.doctype.pricing_rule.utils import update_coupon_code_count
|
||||||
update_coupon_code_count(self.coupon_code,'cancelled')
|
update_coupon_code_count(self.coupon_code,'cancelled')
|
||||||
|
|
||||||
|
def cancel(self):
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
pdb.set_trace()
|
||||||
|
super(SalesOrder, self).cancel()
|
||||||
|
|
||||||
def update_project(self):
|
def update_project(self):
|
||||||
if frappe.db.get_single_value('Selling Settings', 'sales_update_frequency') != "Each Transaction":
|
if frappe.db.get_single_value('Selling Settings', 'sales_update_frequency') != "Each Transaction":
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user