Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make LCV button not working for PI and PR (backport #43592) #43593

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,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: {
Expand Down Expand Up @@ -607,20 +608,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(
Expand All @@ -645,6 +632,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) {
Expand Down
43 changes: 27 additions & 16 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,3 +1370,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()
Loading