fix(Delivery Note): only show permitted actions

(cherry picked from commit 418bdc1dcc)
This commit is contained in:
barredterra
2024-05-08 17:55:16 +02:00
committed by Mergify
parent a0011c5b52
commit cef6d0d74d
2 changed files with 81 additions and 53 deletions

View File

@@ -325,7 +325,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
} }
const me = this; 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)"), () => { this.frm.add_custom_button(__("Quality Inspection(s)"), () => {
me.make_quality_inspection(); me.make_quality_inspection();
}, __("Create")); }, __("Create"));

View File

@@ -79,7 +79,12 @@ frappe.ui.form.on("Delivery Note", {
}, },
refresh: function (frm) { 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( frm.add_custom_button(
__("Credit Note"), __("Credit Note"),
function () { function () {
@@ -93,7 +98,11 @@ frappe.ui.form.on("Delivery Note", {
frm.page.set_inner_btn_group_as_primary(__("Create")); 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; let internal = frm.doc.is_internal_customer;
if (internal) { if (internal) {
let button_label = let button_label =
@@ -140,8 +149,13 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
refresh(doc, dt, dn) { refresh(doc, dt, dn) {
var me = this; var me = this;
super.refresh(); super.refresh();
if (!doc.is_return && (doc.status != "Closed" || this.frm.is_new())) { if (
if (this.frm.doc.docstatus === 0) { !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( this.frm.add_custom_button(
__("Sales Order"), __("Sales Order"),
function () { function () {
@@ -173,9 +187,8 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
__("Get Items From") __("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) { if (doc.docstatus == 1) {
this.frm.add_custom_button( this.frm.add_custom_button(
__("Shipment"), __("Shipment"),
@@ -186,7 +199,11 @@ 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( this.frm.add_custom_button(
__("Installation Note"), __("Installation Note"),
function () { function () {
@@ -194,8 +211,9 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
}, },
__("Create") __("Create")
); );
}
if (doc.docstatus == 1) { if (doc.docstatus == 1 && this.frm.has_perm("create")) {
this.frm.add_custom_button( this.frm.add_custom_button(
__("Sales Return"), __("Sales Return"),
function () { function () {
@@ -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( this.frm.add_custom_button(
__("Delivery Trip"), __("Delivery Trip"),
function () { function () {
@@ -215,8 +233,13 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
); );
} }
if (doc.docstatus == 0 && !doc.__islocal) { if (
if (doc.__onload && doc.__onload.has_unpacked_items) { doc.docstatus == 0 &&
!doc.__islocal &&
doc.__onload &&
doc.__onload.has_unpacked_items &&
frappe.model.can_create("Packing Slip")
) {
this.frm.add_custom_button( this.frm.add_custom_button(
__("Packing Slip"), __("Packing Slip"),
function () { function () {
@@ -228,7 +251,6 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (
__("Create") __("Create")
); );
} }
}
if (!doc.__islocal && doc.docstatus == 1) { if (!doc.__islocal && doc.docstatus == 1) {
this.frm.page.set_inner_btn_group_as_primary(__("Create")); this.frm.page.set_inner_btn_group_as_primary(__("Create"));
@@ -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 // show Make Invoice button only if Delivery Note is not created from Sales Invoice
var from_sales_invoice = false; var from_sales_invoice = false;
from_sales_invoice = me.frm.doc.items.some(function (item) { from_sales_invoice = me.frm.doc.items.some(function (item) {