The best way to express discountAmount, discountPercent in OrderItem?

Hi guys,
When creating a Sales Order Item for a product, I want to append information discounts including: Discount Percent and Discount Amount, I am wondering to do one of the following two ways:

  1. Creating a child item of a product item with ItemTypeEnumId=Discount or something like that. However, Discount Amount must be negative when store in field untiAmount of OrderItem entity
  2. Extend OrderItem entities with two fields: discountPercent and discountAmount. If I do this, I must change service get#OrderItemTotal in OrderService.xml

I want to show order items to users like the following:

Could you give me some advice for the best solution? It’s the first way, second way, or other ways?
Thanks guys!

Have you considered using promotions? There are examples in moqui demo you can look at to see how it is handled out of the box.


Hi Vince,
I have seen examples of promotions in Moqui demo, but it’s not flexible enough with my requirement. Because the users can enter any discount percentage (exp: 1, 2.5, 4, 5,…), and in the case of the decimal part of the discount amount exceeds 2 (maybe 1 or 3) digits, they want to round the number (exp: 1.568 => 1.57).
Do you have any ideas to solve this issue?
Thank you!

I think you are going down the right path by using child items on the order just like promotions do. However, I understand that you want to enter the percent discount in real time rather than a predefined promotion. Here is what I would recommend:
First, as a general rule I do not recommend storing percentages. These are just approximations to arrive at a price. To your point, the math doesn’t always work and must be rounded in the amount field. Storing and passing around percentages just invites problems downstream. You can always back into the percentage discount and discount amount by doing math based on list price and the price the customer was given.
So I see a few options options, two out of the box and one that would require a custom order screen:

  1. Just have your users enter a price the way the order screen works out of the box. They can do easy math outside the system to base the number on a percentage. For example, if something is $100 and they want to give a 20% discount then enter $80 in the price field.
  2. Add a separate order item for the discount using the “Add Other Item” button on the order part. You will still need to manually enter a price, for example -$20 (negative number) rather than entering a percentage. This line would look just like what the promotions create automatically so you are being consistent with out of the box functionality. The advantage of the separate line is to provide flexibility on what you show the customer and / or how you handle the accounting treatment. For example some companies like to track discounts as a separate line item and record it to a separate GL account.
  3. Build a custom order screen so that you can create a new DISPLAY field for the user to enter percentages. Then you will need to have calculation logic on the field to do the math and automatically populate the price field. I emphasize DISPLAY because it will only be used to run a calculation to arrive at a price.

Whatever approach you take, I would NOT recommend adding any new fields to the tables. Based on what you have shared it does not sound like you need additional fields. You just need to think differently about how to solve the requirement based on how Moqui and its data model work out of the box. I almost never find reasons to add fields on Moqui, there is usually a place for everything and as soon as you start adding custom fields it will trigger other customizations that must be made to use the new fields.

1 Like

That great’s!
Thanks for your suggestion, it helps me a lot, I think I will choose your second option

1 Like