Merge pull request #27609 from GangaManoj/unlink-po-on-cancelling-so

fix: Unlink PO on cancelling SO
This commit is contained in:
Deepesh Garg 2021-10-29 11:57:41 +05:30 committed by GitHub
commit 28c116a1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -815,6 +815,38 @@ 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):
so_items = []
for item in self.items:
so_items.append(item.name)
linked_po = list(set(frappe.get_all(
'Purchase Order Item',
filters = {
'sales_order': self.name,
'sales_order_item': ['in', so_items],
'docstatus': ['<', 2]
},
pluck='parent'
)))
if linked_po:
frappe.db.set_value(
'Purchase Order Item', {
'sales_order': self.name,
'sales_order_item': ['in', so_items],
'docstatus': ['<', 2]
},{
'sales_order': None,
'sales_order_item': None
}
)
frappe.msgprint(_("Purchase Orders {0} are un-linked").format("\n".join(linked_po)))
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'):

View File

@ -78,6 +78,8 @@ frappe.ui.form.on("Sales Order", {
}); });
erpnext.queries.setup_warehouse_query(frm); erpnext.queries.setup_warehouse_query(frm);
frm.ignore_doctypes_on_cancel_all = ['Purchase Order'];
}, },
delivery_date: function(frm) { delivery_date: function(frm) {