How to Duplicate a Doctype to Reduce Time Spent on Customization

Can any one kindly show me how to duplicate DocType. For Instance, I want to duplicate Quotation DocYype and use as another DocType. How do I do that with the underlying codes working even if I need to duplicate the child table too?

Thank you.

@Otunba go to doctype list , open your doctype click options then duplicate

Please look at the error message I got while trying to duplicate the Doctype “Quotation” and rename it “Prop”.

How do I solve the problem?

Have you figured this out?
If not, chat me up

Hello, I haven’t. I was actually frustrated and dropped the project. I will appreciate every help I can get from you. I will update local setup I have and look forward to your help to solve the problem.

I need to state that I have been able to duplicate the Doctype, I used custom scripts to calculate some mathematical values but I couldn’t get the Sales Tax to automatically work with my custom scripts. Is that something you can help me with? I can share all the scripts used with you.

Hi, Which version of ERPNext are you using?? Please share the scripts.

Go to the quotation doctype and under Form Settings, uncheck “allow auto repeat”, then rename the field and it should work

I already did that and was able to duplicate the Doctype but Rate and Amount weren’t getting auto-calculated, hence I had to use custom script for that. I now noticed that when I apply Sales Tax to the items in the form, it doesn’t get calculated.

What do I do further?

can i see the script that you used to autopopulate the rate and amount?

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 code above calculates Total and Grand Total

I changed Rate to Unit Price and Amount to Total Price using Translation.

How did you do that?

And is Proposal Item the new name of your duplicated quotation doctype?

Under Translation, one ca change labels. That’s where the changes were made.

Proposal Item is the Child Doctype of Proposal.

I’m trying to look at your code and nothing seems wrong.
Is that all the code you wrote in the proposal.js file?

Maybe seeing the entire code can help or something

Cause I tried to replicate what you did but it didn’t autopopulate, I don’t know if its the translation cause i just used the field names.
So, if you have time, you can try responding and lets see

The code above is working fine and doing its job perfectly.

Here is another code for calculating Taxes below but it’s not working. Here are my problem with the code:

  1. It runs whether I want to calculate Tax or not.
  2. The Tax rate is hard-coded.
  3. The total generated in the initial code I sent above gets erased by this new code.

What I want is once I click on the pre-set tax template, I have the tax auto-calculated and not this hard-coding.

Here is the code:

frappe.ui.form.on("Proposal", {
    validate: function (frm) {
        frm.clear_table("taxes");

        var total_tax_amount = 0;

        $.each(frm.doc.items || [], function (i, item) {
            if (item.item_code) {
                var tax_and_charge = {
                    charge_type: "On Net Total",
                    account_head: "VAT - SGSL",
                    description: "VAT @ 7.5%",
                    rate: 7.5
                };

                var item_tax_amount = (item.amount * tax_and_charge.rate) / 100;
                tax_and_charge.tax_amount = item_tax_amount;
                total_tax_amount += item_tax_amount;

                frm.add_child("taxes", tax_and_charge);
            }
        });

        frm.set_value("total_taxes_and_charges", total_tax_amount);

        var total_taxes = 0;
        $.each(frm.doc.taxes || [], function (i, tax_row) {
            total_taxes += tax_row.tax_amount || 0;
        });
        frm.doc.taxes.forEach(function (row) {
            row.total = total_taxes;
        });
        
      
        var taxes_and_charges_added = (frm.doc.total || 0) + total_tax_amount;
        frm.set_value("taxes_and_charges_added", taxes_and_charges_added);
    
        frm.refresh_field("taxes");
        frm.refresh_field("taxes_and_charges_added");
        frm.refresh_field("total_taxes_and_charges");
    
/**
        var total = (frm.doc.total || 0) + total_tax_amount;
        frm.set_value("total", total);

        frm.refresh_field("taxes");
        frm.refresh_field("total_taxes_and_charges");
        frm.refresh_field("total");
        **/
    }
});

What I sent to you is working perfectly for me. If you use change unit_price to rate and total_price to amount in that code, it will work. Like I stated, I used Translation. Similarly, Did you create a child Doctype for Proposal which ought to be named Proposal Item? That’s supposed to pull the items being listed in the Proposal.

Thank you.