Skip to content

Commit

Permalink
fix(ux): hide Create Purchase Receipt button for Subcontract Return
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Nov 29, 2023
1 parent 874766a commit 7145b04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,51 @@ frappe.ui.form.on('Subcontracting Receipt', {
frappe.set_route('query-report', 'General Ledger');
}, __('View'));

frm.add_custom_button(__('Purchase Receipt'), () => {
frappe.model.open_mapped_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_purchase_receipt',
frm: frm,
freeze: true,
freeze_message: __('Creating Purchase Receipt ...')
});
}, __('Create'));
if (frm.doc.is_return === 0) {
frm.add_custom_button(__('Purchase Receipt'), () => {
frappe.model.open_mapped_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_purchase_receipt',
frm: frm,
freeze: true,
freeze_message: __('Creating Purchase Receipt ...')
});
}, __('Create'));
}
}

if (!frm.doc.is_return && frm.doc.docstatus === 1 && frm.doc.per_returned < 100) {
frm.add_custom_button(__('Subcontract Return'), () => {
frappe.model.open_mapped_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_subcontract_return',
frm: frm
});
}, __('Create'));
frappe.model.open_mapped_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_subcontract_return',
frm: frm
});
}, __('Create'));
frm.page.set_inner_btn_group_as_primary(__('Create'));
}

if (frm.doc.docstatus === 0) {
frm.add_custom_button(__('Subcontracting Order'), () => {
if (!frm.doc.supplier) {
frappe.throw({
title: __('Mandatory'),
message: __('Please Select a Supplier')
});
}

erpnext.utils.map_current_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order.make_subcontracting_receipt',
source_doctype: 'Subcontracting Order',
target: frm,
setters: {
supplier: frm.doc.supplier,
},
get_query_filters: {
docstatus: 1,
per_received: ['<', 100],
company: frm.doc.company
}
if (!frm.doc.supplier) {
frappe.throw({
title: __('Mandatory'),
message: __('Please Select a Supplier')
});
}, __('Get Items From'));
}

erpnext.utils.map_current_doc({
method: 'erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order.make_subcontracting_receipt',
source_doctype: 'Subcontracting Order',
target: frm,
setters: {
supplier: frm.doc.supplier,
},
get_query_filters: {
docstatus: 1,
per_received: ['<', 100],
company: frm.doc.company
}
});
}, __('Get Items From'));

frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', 'read_only', frm.doc.__onload && frm.doc.__onload.backflush_based_on === 'BOM');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,19 @@ def make_subcontract_return(source_name, target_doc=None):
@frappe.whitelist()
def make_purchase_receipt(source_name, target_doc=None, save=False, submit=False, notify=False):
if isinstance(source_name, str):
source_name = frappe.get_doc("Subcontracting Receipt", source_name)
source_doc = frappe.get_doc("Subcontracting Receipt", source_name)
else:
source_doc = source_name

if not source_name.is_return:
if not source_doc.is_return:
if not target_doc:
target_doc = frappe.new_doc("Purchase Receipt")
target_doc.is_subcontracted = 1
target_doc.is_old_subcontracting_flow = 0

target_doc = get_mapped_doc(
"Subcontracting Receipt",
source_name.name,
source_doc.name,
{
"Subcontracting Receipt": {
"doctype": "Purchase Receipt",
Expand All @@ -573,7 +575,7 @@ def make_purchase_receipt(source_name, target_doc=None, save=False, submit=False
)

po_items_details = {}
for item in source_name.items:
for item in source_doc.items:
if item.purchase_order and item.purchase_order_item:
if item.purchase_order not in po_items_details:
po_doc = frappe.get_doc("Purchase Order", item.purchase_order)
Expand All @@ -599,7 +601,7 @@ def make_purchase_receipt(source_name, target_doc=None, save=False, submit=False
if not target_doc.items:
frappe.throw(
_("Purchase Order Item reference is missing in Subcontracting Receipt {0}").format(
source_name.name
source_doc.name
)
)

Expand Down

0 comments on commit 7145b04

Please sign in to comment.