mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-15 23:54:59 +00:00
fix: make LCV button not working for PI and PR (#43592)
This commit is contained in:
@@ -565,11 +565,12 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
frm.custom_make_buttons = {
|
||||
"Purchase Invoice": "Return / Debit Note",
|
||||
"Payment Entry": "Payment",
|
||||
"Landed Cost Voucher": function () {
|
||||
frm.trigger("create_landed_cost_voucher");
|
||||
},
|
||||
};
|
||||
|
||||
if (frm.doc.update_stock) {
|
||||
frm.custom_make_buttons["Landed Cost Voucher"] = "Landed Cost Voucher";
|
||||
}
|
||||
|
||||
frm.set_query("additional_discount_account", function () {
|
||||
return {
|
||||
filters: {
|
||||
@@ -611,20 +612,6 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
});
|
||||
},
|
||||
|
||||
create_landed_cost_voucher: function (frm) {
|
||||
let lcv = frappe.model.get_new_doc("Landed Cost Voucher");
|
||||
lcv.company = frm.doc.company;
|
||||
|
||||
let lcv_receipt = frappe.model.get_new_doc("Landed Cost Purchase Invoice");
|
||||
lcv_receipt.receipt_document_type = "Purchase Invoice";
|
||||
lcv_receipt.receipt_document = frm.doc.name;
|
||||
lcv_receipt.supplier = frm.doc.supplier;
|
||||
lcv_receipt.grand_total = frm.doc.grand_total;
|
||||
lcv.purchase_receipts = [lcv_receipt];
|
||||
|
||||
frappe.set_route("Form", lcv.doctype, lcv.name);
|
||||
},
|
||||
|
||||
add_custom_buttons: function (frm) {
|
||||
if (frm.doc.docstatus == 1 && frm.doc.per_received < 100) {
|
||||
frm.add_custom_button(
|
||||
@@ -649,6 +636,32 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
__("View")
|
||||
);
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus === 1 && frm.doc.update_stock) {
|
||||
frm.add_custom_button(
|
||||
__("Landed Cost Voucher"),
|
||||
() => {
|
||||
frm.events.make_lcv(frm);
|
||||
},
|
||||
__("Create")
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
make_lcv(frm) {
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_lcv",
|
||||
args: {
|
||||
doctype: frm.doc.doctype,
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
callback: (r) => {
|
||||
if (r.message) {
|
||||
var doc = frappe.model.sync(r.message);
|
||||
frappe.set_route("Form", doc[0].doctype, doc[0].name);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
onload: function (frm) {
|
||||
|
||||
@@ -11,25 +11,10 @@ erpnext.buying.setup_buying_controller();
|
||||
|
||||
frappe.ui.form.on("Purchase Receipt", {
|
||||
setup: (frm) => {
|
||||
frm.make_methods = {
|
||||
"Landed Cost Voucher": () => {
|
||||
let lcv = frappe.model.get_new_doc("Landed Cost Voucher");
|
||||
lcv.company = frm.doc.company;
|
||||
|
||||
let lcv_receipt = frappe.model.get_new_doc("Landed Cost Purchase Receipt");
|
||||
lcv_receipt.receipt_document_type = "Purchase Receipt";
|
||||
lcv_receipt.receipt_document = frm.doc.name;
|
||||
lcv_receipt.supplier = frm.doc.supplier;
|
||||
lcv_receipt.grand_total = frm.doc.grand_total;
|
||||
lcv.purchase_receipts = [lcv_receipt];
|
||||
|
||||
frappe.set_route("Form", lcv.doctype, lcv.name);
|
||||
},
|
||||
};
|
||||
|
||||
frm.custom_make_buttons = {
|
||||
"Stock Entry": "Return",
|
||||
"Purchase Invoice": "Purchase Invoice",
|
||||
"Landed Cost Voucher": "Landed Cost Voucher",
|
||||
};
|
||||
|
||||
frm.set_query("expense_account", "items", function () {
|
||||
@@ -114,9 +99,35 @@ frappe.ui.form.on("Purchase Receipt", {
|
||||
}
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus === 1) {
|
||||
frm.add_custom_button(
|
||||
__("Landed Cost Voucher"),
|
||||
() => {
|
||||
frm.events.make_lcv(frm);
|
||||
},
|
||||
__("Create")
|
||||
);
|
||||
}
|
||||
|
||||
frm.events.add_custom_buttons(frm);
|
||||
},
|
||||
|
||||
make_lcv(frm) {
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_lcv",
|
||||
args: {
|
||||
doctype: frm.doc.doctype,
|
||||
docname: frm.doc.name,
|
||||
},
|
||||
callback: (r) => {
|
||||
if (r.message) {
|
||||
var doc = frappe.model.sync(r.message);
|
||||
frappe.set_route("Form", doc[0].doctype, doc[0].name);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
add_custom_buttons: function (frm) {
|
||||
if (frm.doc.docstatus == 0) {
|
||||
frm.add_custom_button(
|
||||
|
||||
@@ -1361,3 +1361,26 @@ def get_item_account_wise_additional_cost(purchase_document):
|
||||
@erpnext.allow_regional
|
||||
def update_regional_gl_entries(gl_list, doc):
|
||||
return
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_lcv(doctype, docname):
|
||||
landed_cost_voucher = frappe.new_doc("Landed Cost Voucher")
|
||||
|
||||
details = frappe.db.get_value(doctype, docname, ["supplier", "company", "base_grand_total"], as_dict=1)
|
||||
|
||||
landed_cost_voucher.company = details.company
|
||||
|
||||
landed_cost_voucher.append(
|
||||
"purchase_receipts",
|
||||
{
|
||||
"receipt_document_type": doctype,
|
||||
"receipt_document": docname,
|
||||
"grand_total": details.base_grand_total,
|
||||
"supplier": details.supplier,
|
||||
},
|
||||
)
|
||||
|
||||
landed_cost_voucher.get_items_from_purchase_receipts()
|
||||
|
||||
return landed_cost_voucher.as_dict()
|
||||
|
||||
Reference in New Issue
Block a user