Skip to content

Commit

Permalink
fix(Delivery Note): only show permitted actions
Browse files Browse the repository at this point in the history
(cherry picked from commit 418bdc1)
  • Loading branch information
barredterra authored and mergify[bot] committed May 13, 2024
1 parent a0011c5 commit cef6d0d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 53 deletions.
2 changes: 1 addition & 1 deletion erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}

const me = this;
if (!this.frm.is_new() && this.frm.doc.docstatus === 0) {
if (!this.frm.is_new() && this.frm.doc.docstatus === 0 && frappe.model.can_create("Quality Inspection")) {
this.frm.add_custom_button(__("Quality Inspection(s)"), () => {
me.make_quality_inspection();
}, __("Create"));
Expand Down
132 changes: 80 additions & 52 deletions erpnext/stock/doctype/delivery_note/delivery_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ frappe.ui.form.on("Delivery Note", {
},

refresh: function (frm) {
if (frm.doc.docstatus === 1 && frm.doc.is_return === 1 && frm.doc.per_billed !== 100) {
if (
frm.doc.docstatus === 1 &&
frm.doc.is_return === 1 &&
frm.doc.per_billed !== 100 &&
frappe.model.can_create("Sales Invoice")
) {
frm.add_custom_button(
__("Credit Note"),
function () {
Expand All @@ -93,7 +98,11 @@ frappe.ui.form.on("Delivery Note", {
frm.page.set_inner_btn_group_as_primary(__("Create"));
}

if (frm.doc.docstatus == 1 && !frm.doc.inter_company_reference) {
if (
frm.doc.docstatus == 1 &&
!frm.doc.inter_company_reference &&
frappe.model.can_create("Purchase Receipt")
) {
let internal = frm.doc.is_internal_customer;
if (internal) {
let button_label =
Expand Down Expand Up @@ -140,42 +149,46 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
refresh(doc, dt, dn) {
var me = this;
super.refresh();
if (!doc.is_return && (doc.status != "Closed" || this.frm.is_new())) {
if (this.frm.doc.docstatus === 0) {
this.frm.add_custom_button(
__("Sales Order"),
function () {
if (!me.frm.doc.customer) {
frappe.throw({
title: __("Mandatory"),
message: __("Please Select a Customer"),
});
}
erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
args: {
for_reserved_stock: 1,
},
source_doctype: "Sales Order",
target: me.frm,
setters: {
customer: me.frm.doc.customer,
},
get_query_filters: {
docstatus: 1,
status: ["not in", ["Closed", "On Hold"]],
per_delivered: ["<", 99.99],
company: me.frm.doc.company,
project: me.frm.doc.project || undefined,
},
if (
!doc.is_return &&
(doc.status != "Closed" || this.frm.is_new()) &&
this.frm.has_perm("write") &&
frappe.model.can_read("Sales Order") &&
this.frm.doc.docstatus === 0
) {
this.frm.add_custom_button(
__("Sales Order"),
function () {
if (!me.frm.doc.customer) {
frappe.throw({
title: __("Mandatory"),
message: __("Please Select a Customer"),
});
},
__("Get Items From")
);
}
}
erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
args: {
for_reserved_stock: 1,
},
source_doctype: "Sales Order",
target: me.frm,
setters: {
customer: me.frm.doc.customer,
},
get_query_filters: {
docstatus: 1,
status: ["not in", ["Closed", "On Hold"]],
per_delivered: ["<", 99.99],
company: me.frm.doc.company,
project: me.frm.doc.project || undefined,
},
});
},
__("Get Items From")
);
}

if (!doc.is_return && doc.status != "Closed") {
if (!doc.is_return && doc.status != "Closed" && frappe.model.can_create("Shipment")) {
if (doc.docstatus == 1) {
this.frm.add_custom_button(
__("Shipment"),
Expand All @@ -186,16 +199,21 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
);
}

if (flt(doc.per_installed, 2) < 100 && doc.docstatus == 1)
if (
flt(doc.per_installed, 2) < 100 &&
doc.docstatus == 1 &&
frappe.model.can_create("Installation Note")
) {
this.frm.add_custom_button(
__("Installation Note"),
function () {
me.make_installation_note();
},
__("Create")
);
}

if (doc.docstatus == 1) {
if (doc.docstatus == 1 && this.frm.has_perm("create")) {
this.frm.add_custom_button(
__("Sales Return"),
function () {
Expand All @@ -205,7 +223,7 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
);
}

if (doc.docstatus == 1) {
if (doc.docstatus == 1 && frappe.model.can_create("Delivery Trip")) {
this.frm.add_custom_button(
__("Delivery Trip"),
function () {
Expand All @@ -215,19 +233,23 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
);
}

if (doc.docstatus == 0 && !doc.__islocal) {
if (doc.__onload && doc.__onload.has_unpacked_items) {
this.frm.add_custom_button(
__("Packing Slip"),
function () {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
frm: me.frm,
});
},
__("Create")
);
}
if (
doc.docstatus == 0 &&
!doc.__islocal &&
doc.__onload &&
doc.__onload.has_unpacked_items &&
frappe.model.can_create("Packing Slip")
) {
this.frm.add_custom_button(
__("Packing Slip"),
function () {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_packing_slip",
frm: me.frm,
});
},
__("Create")
);
}

if (!doc.__islocal && doc.docstatus == 1) {
Expand All @@ -254,7 +276,13 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
}
}

if (doc.docstatus == 1 && !doc.is_return && doc.status != "Closed" && flt(doc.per_billed) < 100) {
if (
doc.docstatus == 1 &&
!doc.is_return &&
doc.status != "Closed" &&
flt(doc.per_billed) < 100 &&
frappe.model.can_create("Sales Invoice")
) {
// show Make Invoice button only if Delivery Note is not created from Sales Invoice
var from_sales_invoice = false;
from_sales_invoice = me.frm.doc.items.some(function (item) {
Expand Down

0 comments on commit cef6d0d

Please sign in to comment.