I haven’t really done anything with tax before, hence why I can’t help
I only reached out cause I thought you were having issues duplicating quotation doctype which I was able to do
But the issue I had after duplicating it was being unable to autopopulate the rate and amount columns, that’s why I asked for the script.
So at this point,I think its your help I need, so if you can help, I’ll appreciate
I’m also on a project like that to create a quotation duplicate and create a sales invoice from the quotation, that’s what I mean, I need help in auto populating the rate and amount once I select the item code, a link to your github repo could also assist me
This will work for you:
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
});
function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function (item) {
total += item.amount;
});
frm.set_value("total", total);
}
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateGrandTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
});
function calculateGrandTotal(frm) {
var grand_total = 0;
frm.doc.items.forEach(function (item) {
grand_total += item.amount;
});
frm.set_value("grand_total", grand_total);
}
However, from which Doctype did you duplicate your main Doctype-Proposal? Did you also have a functional Child Doctype which should be named Proposal Item for the code above to work? Did you duplicate the child Doctype?
You don’t need to re-create Quotation Doctype in that case. Quotation is already pre-loaded and it should be working perfectly. You might only need to add more field as per your customization.
I just created a new doctype and added fields like customer and the rest that are needed on the doctype, then I duplicated the quotation item as the child table and added the child table to my custom doctype
Now, when I pick the item, it doesn’t autopopulate the rate and amount?
Do you get now?
What is the name of the new Doctype you created?
Shopify and the child doctype name is shopify item
- Did you reference Shopify Item inside Shopify?
- Did you edit the code from Proposal Item to Shopify Item?
Yes,I did
Can i see the source code to just see how it goes, so that I can figure it out?
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateTotal(frm);
},
});
function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function (item) {
total += item.amount;
});
frm.set_value("total", total);
}
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateGrandTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.rate);
calculateGrandTotal(frm);
},
});
function calculateGrandTotal(frm) {
var grand_total = 0;
frm.doc.items.forEach(function (item) {
grand_total += item.amount;
});
frm.set_value("grand_total", grand_total);
}
Change Proposal Item to Shopify Item.
Also, reference Shopify Item in your Shopify Doctype.
Can I get the link to your github repo?, that could help me in many ways
And the shopify item (child doctype) doesn’t come with a js file, do I need to create that manually myself or should that code be just put in the Shopify.js file?
And I already changed the proposal item to shopify item
Unfortunately, my Git Repo is a virgin.
The code I sent you can be added under Custom Scripts. It will work that way. You don’t need any .py file.
Alright, thank you for your help so far
It’s my pleasure. Someone here helped me out too.
I am sincerely sorry, how could I have missed out on your offer to help me? I am just seeing thins now. I am using version 14 please.
Here is the code for calculating the Total and Grand Total. Please note that I have changed Rate to Unit Price and Amount to Total Price.
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "total_price", d.qty * d.unit_price);
calculateTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "total_price", d.qty * d.unit_price);
calculateTotal(frm);
},
});
function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function (item) {
total += item.total_price;
});
frm.set_value("total", total);
}
frappe.ui.form.on("Proposal Item", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
if (child.item_code) {
calculateGrandTotal(frm);
}
},
qty: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "total_price", d.qty * d.unit_price);
calculateGrandTotal(frm);
},
unit_price: function (frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "total_price", d.qty * d.unit_price);
calculateGrandTotal(frm);
},
});
function calculateGrandTotal(frm) {
var grand_total = 0;
frm.doc.items.forEach(function (item) {
grand_total += item.total_price;
});
frm.set_value("grand_total", grand_total);
}
The above code works fine, the challenge here is that, if I try applying the set Sales Tax VAT of 7.5% already setup in the Tax template which works for other modules that comes installed in ERPNext 14, the VAT gets applied for those ones but never works for the Proposal Module which I duplicated from Quotation Module.
Is there any way I can solve this?
Thanks, Lets try to make it simpler, and use this code instead of all the above code and check,
frappe.ui.form.on("Main Doctype Name", {
item_code: function (frm, cdt, cdn) {
var child = locals[cdt][cdn];
frm.script_manager.trigger("item_code", child.doctype, child.name);
},
});
Try this and let me know.