Purchase Order item missing project value

Hi All,
We have started having issues with creating purchases with more than one item.
Items 2 and onwards miss the project value and return an error. We need to manually enter the project value for each item.
Can someone please check and see if they have the same issue?

To create purchases, we follow this process:
Go to project → Dashboard → Press + next to the purchase order.
A new purchase order form opens, and the project code is prepopulated on the main form.
Add supplier.
Set Required By Date
Add more than one item to the purchase order.

Following these steps, we receive the below Error:

Mandatory fields required in table Items, Row 2

*** Project**

PO item missing project

Regards,
Saeed

Which version?

Because we tested the same process in v15, so we haven’t found the issue. If there are any validation set on server/client side? if set then check that.

we are on the cloud
ERPNext: v15.32.1 (HEAD)
Frappe Framework: v15.37.0 (HEAD)

We haven’t got any customisation around this, I believe. The only change would be we have made the Project field mandatory.

Can you please check to see if the items have the project values in them?

thanks,

Yes, if the Project field is mandatory, it should be set in the first row. If you add another row, the project field will not show up automatically. If you want to set the project in the child table based on the parent value, then you need to set the server/client script on the before save event.

i don’t see any server script code but there is a client script as below.

frappe.ui.form.on('Purchase Order', 'onload', function(frm) {
    let table = cur_frm.doc.items;
    let projectSource;
    table.forEach(row => {
        if (row.project) projectSource = row.project;
    })
    cur_frm.doc['project'] = projectSource;
    frm.refresh_field('project');
})

it was working until recently. Maybe it is not compatible with some of the recent updates?

can you please let me know how the server script would be? if that is a better place for this code?

Please use below client script.

frappe.ui.form.on('Purchase Order Item', {
    items_add: function(frm, cdt, cdn) {
        frappe.model.set_value(cdt, cdn, 'project', frm.doc.project);
    }
});

When click on add a row, then it will automatically set the project. I tested so it worked properly.

This solved the problem and works perfectly.
Thank you very much @NCP :pray:

One more item we realised is still causing issues for us.
When we create and submit a Purchase Order, we sometimes need to update or add new items to an already submitted PO.

We use Update Items button to update the pricing and also add missing items later.

The script above doesn’t work for that update items form. @NCP can you please help get items those items sorted as well?