How to add Rate & Amount fields to Material Request and carry them to Purchase Order?

Hello everyone,

I am configuring ERPNext for our procurement workflow and would appreciate some guidance.

Goal

We want to use Material Request (Purchase Request) with pricing, so that:

  1. Each Material Request Item has:

    • Rate (Unit Price)

    • Amount (Qty × Rate)

  2. Material Request shows a Total Amount.

  3. When creating a Purchase Order from a Material Request, the Rate and Amount values are automatically carried over to the PO.

What I Tried

  • Created Custom Fields:

    • On Material Request Item:

      • custom_rate (Currency)

      • custom_amount (Currency)

    • On Material Request:

      • custom_total_amount (Currency)
  • Tried Client Script to calculate:

    • custom_amount = qty * custom_rate

    • Sum all rows into custom_total_amount

Problem

After adding scripts and custom fields, I started getting server errors when opening or creating Material Requests:

TypeError: '<' not supported between instances of 'NoneType' and 'int'
Field workflow_state not found

Even after disabling/deleting the scripts and custom fields, the errors persisted.

Material Request was working correctly before these changes.

Questions

  1. Is there a recommended / standard way in ERPNext to support pricing in Material Request?

  2. Should Rate and Amount be added via:

    • Custom Fields?

    • Property Setter?

    • Server Script?

  3. What is the correct approach to map these values from Material Request → Purchase Order?

  4. How can I safely clean up or revert broken customizations causing server errors?

Any advice, examples, or documentation would be greatly appreciated.

Thank you!

Does Material Request currently have a Workflow enabled?

The workflow_state field is only created when a Workflow is configured for a DocType.

The error suggests that some customization (Client Script, Server Script, or Property Setter) may still be referencing workflow_state

Could you please check whether:

  • Any Workflow exists (active or disabled) for Material Request

  • Any script or customization is referencing workflow_state