How to let erpnext generate qty of item automatically when creating sale order?

how can I configure the order creation process to have the product quantity calculated automatically based on a value I input? Generally, when creating a sales order, directly input the qty of items is needed. However, in my use case I sell plank, where each plank covers 0.238 square meters, customers will tell me how much square meters of plank they need. Since planks cannot be divided, I need to

  1. Calculate the corresponding number of planks required
    
  2. Round up to the nearest whole number to obtain the actual quantity to be sold
    
  3. Use this plank count to determine the actual square meters being sold
    
  4. Multiply by the price per square meter to calculate the total amount
    

I want to know how can I let erpnext calculate the actual square meters will be sold according to the square meters I input. Any advice will be greatly appreciate.

First, do you have UOM conversion in place for .238 SQ Meter = 1 Plank?
Do you have an Item Price for each Plank?

You should start with the above then looking into fractions UOM.

Thanks for your advice, I tried, but it didn’t work for my use case. I created an item named ‘plank’, set ‘Nos’ (which must be a whole number) as the default UoM, and added ‘SQ Meter’ with the conversion fraction set to 1/0.238. Then, I added the sale price for ‘plank’ with both ‘SQ Meter’ and ‘Nos’. However, when I created a sale order and entered ‘SQ Meter’ for ‘plank’, the ‘QTY as per stock’ field still showed a fractional number.

Can you provide some screenshots showing the conversion results (like below)?

item

price

sale order

Nos is a “must be whole number” UoM, and I can’t save this sale order.

Are you able to change “210.1” to “211” and see the sqM increase automatically?

No, it can’t be changed manually

I’m not an expert in this workflow. Perhaps others can chime in. It looks like you may need a custom script to update the quanty sold by the conversion factor to bring stock UOM to a whole number.

thank you for your help, it’s a good direction, I’ll read some document about erpnext script trying to find out the solution.

After trying custom script, I find out a workaround solution.
set the plank default UoM as SQ Meter, and selling UoM as Nos. Then added the following client script to erp system. Then, every item belonging to plank category or it’s descendant category when it’s added to sales order items, the script will automatically transform the inputted SQ Meter qty customer wanted Nos qty.

frappe.ui.form.on('Sales Order Item', {
    qty(frm, cdt, cdn) {
        let row = frappe.get_doc(cdt, cdn);
        frappe.call({
            method: "frappe.client.get_value",
            args: {
                doctype: "Item",
                fieldname: ["item_group"],
                filters: {
                    name: row.item_code
                }
            },
            callback: function(r) {
                if (!r.exc && r.message.item_group) {
                    frappe.call({
                        method: "frappe.client.get_value",
                        args: {
                            doctype: "Item Group",
                            fieldname: ["parent_item_group"],
                            filters: {
                                name: r.message.item_group
                            }
                        },
                        callback: function(r2) {
                            const full_group_hierarchy = [r.message.item_group];
                            if (r2.message.parent_item_group) {
                                full_group_hierarchy.push(r2.message.parent_item_group);
                            }

                            if (full_group_hierarchy.includes("plank")) {
                                frappe.msgprint(`${row.conversion_factor}`);
                                row.qty = Math.ceil(row.qty / row.conversion_factor);
                            }
                        }
                    });
                }
            }
        });
    }
})