Request for Total Purchase Order Script in Project Field

Dear All,

We have new requirement to add in Total Purchase Order field respective to every Project.

May I know if anyone had done the custom script for Total Purchase order (via Purchase Order) field in Project Doctype.

Thank you

Regards
Charnack

  1. add the new field total_po_cost to project doctype via customize form
  2. add the following python script for both Submit and Cancel events of doctype Purchase Order.
projects = {po_item.project for po_item in doc.items}
for project in projects:
    po_cost = frappe.get_list('Purchase Order', 
                                fields = 'sum(grand_total)',
                                filters = {'project': project, 'docstatus': 1},
                                as_list = 1)[0][0]
    frappe.db.set_value('Project',project, 'total_po_cost', po_cost or 0)

Thanks for your prompt reply. I will try it out.

Thankss.

Hi Szufisher,

I try to understand on this line.

projects = {po_item.project for po_item in doc.items}

Fieldname po_item is new added field to project doctype?
Sorry I couldnot find any of the po_item field in project by default.

Thank you

this line is python list comprehension which returns a set of unique project number.

Do I have to modified the code?

Question No 2:
2. add the following python script for both Submit and Cancel events of doctype Purchase Order
May I know how can I perform this step?

I had add in custom script as per yours, but the total PO does not show the total.

  1. add new field via customize form for doctype Project
  2. create two server script for doctype Purchase Order

  1. create purchase order with project linked in item, submit purchase order

  2. goto project form, refresh browser, check the new total po cost field.

Thank you so much. its work.