Make changes in line_items module

Hello,

I have added custom field discount in products module. Now I want to display the discount value from products module to quotes module line items like other fields such as product name, part number etc and I want calculation of Total amount to be same as previous.

Would be great if any response for the query.

Thanks in advance

Displaying Discount Value in Quotes Line Items

SuiteCRM doesn’t allow extending standard modules directly. You’ll need to create a Relationship Link. This link will connect the Products module (parent) to the Quotes module (child), allowing you to access the discount field from the Products module within Quotes line items.

  1. Go to Studio > Relationships.
  2. Click on “Create” and select “Relationship.”
  3. Fill in the details:
  • Module Name: Quotes
  • Related Module Name: Products
  • Relationship Name: discount_rel
  • Relationship Type: One-to-Many
  1. Under “Link Information,” select “Products” in the “From” dropdown and “Quote Line Items” in the “To” dropdown.
  2. Click “Save.”

This will create a link between Products and Quotes line items. Now you can access the discount field from the Products module within the Quotes line items.

Adding Discount Value to Quote Line Items View

  1. Navigate to Studio > Quotes > Layouts.
  2. Select the layout you want to modify (Edit View or Detail View).
  3. In the “Fields” section, locate the “discount_rel” relationship link.
  4. Drag the “discount” field (from the Products module) to the desired location on the layout.
  5. Click “Save.”

This will add the discount field from the Products module to the Quotes line items view.

Preserving Total Amount Calculation

By default, SuiteCRM calculates the total amount based on the unit price and quantity in the Quotes line items. Since you’re introducing a discount field, you’ll need to modify the calculation logic to consider the discount.

There are two ways to achieve this:

  1. Workflows: Create a workflow that triggers on save in the Quotes module. The workflow should loop through the Quotes line items, retrieve the discount value from the linked product, and calculate the discounted unit price. Finally, update the Quotes line item with the discounted unit price before recalculating the total amount.
  2. Custom Code: You can inject custom PHP code into the Quotes module logic to modify the total amount calculation during the save process. This code would access the discount from the linked product and apply it to the unit price before calculating the final total amount.

Important Note: Modifying SuiteCRM core files is not recommended as it can cause issues during upgrades and modified core files would be overwritten with the upgraded core files. Best to use the Workflows approach as it’s the upgrade-safe way to achieve the desired functionality.

Additional Tips

  • You can create a custom formula field in Quotes line items to display the discounted unit price. This field would reference the unit price, quantity, and discount from the linked product.
  • Thoroughly test your changes in a non-production environment before deploying them to your live system.

By following these steps, you can display the discount value from the Products module in Quotes line items while maintaining the original total amount calculation logic with some adjustments.

1 Like

Hi chris001

Thanks for the response.

I hope you are telling about how to insert the field from product module to quote module. But I want that ,in line items there is already a field named discount . for that discount field i want to display the value from products module discount field. Is it possible to do that.

Sure, you can display your Products module’s custom field “discount”, in the Line Items module, by customizing your Line Items module.

However, why not use the built in Discount feature, for Line Items, showing on Quotes?

Well, I want every details of the product should be fetched from the products module itself, I don’t want to enter discount amount separately in Quotes line items, so i am trying to do this.

And In the steps you provided above

  1. Go to Studio > Relationships.
  2. Click on “Create” and select “Relationship.”
  3. Fill in the details:
  • Module Name: Quotes
  • Related Module Name: Products
  • Relationship Name: discount_rel
  • Relationship Type: One-to-Many
  1. Under “Link Information,” select “Products” in the “From” dropdown and “Quote Line Items” in the “To” dropdown.
  2. Click “Save.”

I am able create Relationship among the modules, I did not get 4th point i.e Link Information.
Could you please let me know, where can I get Link Information to fill from and to details.

Thank you.