Additional Quantity field for Quoted Line Items

Dear Sugar Community,

I have a question relating to quoted line items. We have the need to add an additional field to the quoted line item, this field will be known as a “term”, i.e. a term of 1 year 1.5 years 2 years etc.

I need the “term” value to also be used within the calculations of the quoted line item totals.

I can see that there are several calculated value fields within the QLIs. i.e.

  • Discount Total
  • Subtotal
  • Line Item Total

These calculated values all use the Quantity field within their calculation.

My first thought was to change each calculation formula to include the term within the calculation, i.e. the $term_c would become a new factor in the formula.

Another option would be to create a new calculated field being a new quantity field, i.e.

multiply($quantity, $term_c)

Then use this in the calculations listed above.

I’m attempting both approaches, however when I edit the formula, I can not save it as I receive this error.

Unknown field: discount_amount

However, this field exists in my QLIs, as you can see.

  • Has anyone experienced this issue?
  • Is there a work around, for example, can I edit the vardef.php for Products, to change the “Formula” to include my new “quantity” field in the calculation?
  • Or does anyone have an alternate suggestion?

Many thanks for any assistance.  

Sugar version details:

  • SugarCRM Version 11.0.0 (Build 238 P) (Q2 2021)
  • Professional
  • On-Premise

 

Parents
  • It has been a long time since I customized my Quotes but I think the discount_amount is the percentage or currency amount of the discount, while the discount_price might be what you are after.

    What I would suggest is manipulating the formula for the total_amount on the quoted line via studio or code ( custom/Extension/modules/Products/Ext/Vardefs/sugarfield_total_amount.php ) to include the multiplication for the newly added term, although

    I suppose you could try to manipulate the discount_price to reflect the term quantity, but I think you might need to disable the readonly on that field (see: https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1179/new-quotes-modules-how-to-update-the-current-qli-based-on-field-change/4778#4778 )

    Also be sure to add your new field to the related_fields of the Quote's record view metadata:

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.3/Architecture/Quotes/#Adding_Custom_Related_Fields_to_Model

    Sorry for the somewhat vague response, I hope this gives you some ideas though.

    Good luck,

    FrancescaS

  • Hi Francesca, 

    Thanks again for your help with this issue, and all the issues over the years. You are a true wealth of knowledge. 

    There were two VarDef files I need to modify, 

    custom/Extension/modules/Products/Ext/Vardefs/sugarfield_subtotal.php

    and 

    custom/Extension/modules/Products/Ext/Vardefs/sugarfield_total_amount.php

    I basically added my new "term" field to the multiplication function of the $discount_price and $quantity i.e. 

    multiply($discount_price, $quantity, $term_c),
    Plus some isNumeric() tests where relevant. 

    The formula for both fields needed to be overridden as the "total_amount" references the "subtotal" in its formula.

    The strange thing is, I could not edit the formula via studio as  I would receive this error when trying to save the formula.

    Unknown field: discount_amount

    As mentioned above, the discount_amount is a valid field. As you can see in Studio.

    However I can not use it in the Formula Builder, 

    It is some how hidden from the Formula Builder. However I can add it via the Vardef file. 

    Any clues?

  • This rings a bell as something I reported in the past... but I can't seem to find the case in question in my portal. You may want to open a case with Support, they should be able to dig it up...

    I don't have discount_amount in studio either, yet I am using it in the formula.
    I think in the end I edited the vardef php file instead of going through Studio.

    This is a screenshot from Studio, as you can see the field is not there, yet I'm clearly using it in the formula

    This is my custom/Extension/modules/Products/Ext/Vardefs/sugarfield_total_amount.php

    <?php
    $dictionary['Product']['fields']['total_amount']['formula'] =
    'ifElse(and(isNumeric(toString($quantity)), isNumeric(toString($discount_price))),
      currencyMultiply(
        round(
          subtract(
            $discount_price,
            ifElse(equal($discount_select, "1"),
              multiply($discount_price, divide($discount_amount, 100)),
              ifElse(isNumeric(toString($discount_amount)), $discount_amount, 0)
            )
          ),
        2),
        $quantity
     ),
     ""
    )';

  • Peter / Francesca,

    I think the issue here is that Studio does not necessarily allow all fields in a module to be used in formulae. Only those fields allowed can be added via the formula builder. A good example of this is if you try to use "id" as a field in a formula in Studio - I believe it will give the same message although clearly "id" exists for all objects.

    When you add the formula manually, using the vardef attribute, you are bypassing the Studio checker and so it will work as long as the field really exists.

    If you look in the cached Vardefs for Products: ./cache/modules/Products/Productvardefs.php you will see that the field "discount_amount" has special attributes, a field type of "discount" and an attribute set for "related_fields". I guess this means it is a special field that relies on others to be used and therefore I suspect this might be why it is banned in Studio's formula builder.

    I don't think it is a bug - Studio has always been like this and there have always been fields that cannot be used in this way.

    If you are happy with adding the attribute manually in the vardefs file then I'd just go with that.

    Thanks,

    JH.

  • Thanks John, 

    Makes sense. I was concerned it was an issue with our Sugar Instance. I appreciate your help and also thanks

Reply Children
No Data