Beta: Quote Template Customization - Updating Item Amount

SOLVE
amandaulm
Contributor

Brief background: Our business model is SLA-based and we quote and bill weekly based on a standard weekly rate and a number of units of coverage, but weekly billing is not an option in Hubspot quote line items. This whole thing is meant to address that and make the quote calculations work for us (we just choose one-time billing frequency since weekly isn't an option). If this can't work, our sales team will have to manually calculate our weekly quote price for the term length and enter that as the unit price, which introduces a lot of human error potential - and then I'll have to include a calculated line item column to reduce that amount back to our weekly rate so the customer can see it on the quote.

 

Side note: As I was working on this problem, I also noticed that the hs_term_in_months variable now returns a null value, where it used to return the term length as an integer. The next best thing I could find in the console output was a hs_recurring_billing_period string in the format P#M, where # is the term length integer I need. Hence the lineitem_term variable I'm setting here, to work around that problem.

 

OK, so - what I want to happen in each line item is for the Total column to calculate correctly based on what the term length (months) is, and also update the item.amount value with that amount, so that the subtotals and totals at the bottom work correctly. Here's what I've tried:

 

1) Using a set item.amount type of update did not adjust the item.amount fields at all. I assume this is a variable scope discrepancy.

 

 

 

2) This was based on an old forum post answer I found that mentioned using do item.update as a workaround to solve the variable scope problem.

It looks like this calculates the line item totals correctly, but it doesn't actually update the global item.amount values, so the overall subtotal and totals at the bottom are still incorrect:

 

 

 

 

{% for item in LINE_ITEMS|sort(False, False, 'hs_position_on_quote') %}
<script>
console.table(`{{item}}`);
</script>
            {% set lineitem_term = (item.hs_recurring_billing_period|regex_replace("P|M","")|int ) %}
            <tr>
              <td>{{ item.name }}</td>
              {# <td>{{ item.hs_sku }}</td>  #}
              <td>
                  {{ item.price|format_currency(LOCALE, CURRENCY, true) }}
              </td>
              <td>{{ item.additional_hour_rate|format_currency(LOCALE, CURRENCY, true) }}</td>
              <td>{{ item.quantity }}</td>
              <td>{{ item.hs_recurring_billing_start_date|int|datetimeformat('%m/%d/%y') }}</td>
              <td>{#{{ item.hs_term_in_months }}#}{{ lineitem_term[0] }} mo.</td>
              <td>
                  {% if item.discount %}
                    after {{ item.discount|format_currency(LOCALE, CURRENCY, true) }} discount
                  {% endif %}</td>
              <td>
                {% if item.quantity == 0 %}
                  As Needed
                {% elif lineitem_term[0] == 3 %}
                  {% do item.update({amount: item.amount*13}) %}
                  {{ item.amount|format_currency(LOCALE, CURRENCY, true) }}
                {% elif lineitem_term[0] == 6 %}
                  {% do item.update({amount: item.amount*26}) %}
                  {{ item.amount|format_currency(LOCALE, CURRENCY, true) }}
                {% elif lineitem_term[0] == 12 %}
                  {% do item.update({amount: item.amount*52}) %}
                  {{ item.amount|format_currency(LOCALE, CURRENCY, true) }}
                {% else %}
                  {% do item.update({amount: item.amount*lineitem_term[0]*4}) %}
                  {{ item.amount|format_currency(LOCALE, CURRENCY, true) }}
                {% endif %}
                </td>
            </tr>
            {% endfor %}

 

 

 

Does anyone have an idea of how to correctly update the global item.amount values to address the issue of the overall quote subtotal and total calculations?

0 Upvotes
2 Accepted solutions

Accepted Solutions
jmclaren
Solution
HubSpot Employee

There's a lot of context to try to wrap my head around in this thread so I apologize ahead of time if I miss something specific.

Here's what I understand you are trying to do @amandaulm You want to manually display a different value on the quote page for the quote total, than what is calcualted on the back end in the quote/deal itself.

1. be aware that if the user approves this, the value that is still in the database is the one that's in the back-end. Since it displays different that means your numbers would be off in associating deals etc.

2. You were talking about scopes and looping through line items. When you are in a loop you can't use set, to update a variable outside the loop.
https://developers.hubspot.com/docs/cms/hubl/for-loops#variables-within-loops

You can update objects however using do:
https://developers.hubspot.com/docs/cms/hubl/variables-macros-syntax#variables-within-loops 

You could create an object outside of the loop, with just one parameter in it - the value you want to be your "total". Then in your loop perform whatever math you need to on it. Then display that resulting value.


Unfortunately in regards to support - you have been redirected back here because what you are trying to do is outside of what this functionality was intended for. The custom quote templates functionality was originally intended so companies could simply make quotes visually fit their brand's aesthetics.

The team in charge of this beta has seen that folks have had further customization ideas beyond the original intent for the feature, and as a result has been working on changes to make it easier for developers to expand upon what quote templates can do.
https://community.hubspot.com/t5/HubSpot-Ideas/Customize-Quote-template-appearance/idi-p/193644


What you are aiming to do is further customize the actual calculation of quotes and display something other than what is entered into the quote in the back-end. If you want official support for alternate ways of calculating quotes I'd advise submitting those ideas to the idea forum for that the quotes team can see the demand for the functionality, and officially support it instead.

Jon McLaren

Sr. CMS Developer Advocate

If my reply answered your question, please mark it as a solution, to make it easier for others to find.

View solution in original post

amandaulm
Solution
Contributor

Hi Jon. I appreciate your response.

 

Point 1) has been the deciding factor on my giving up on this functionality. Even if we could do exactly what I'm looking for with the quote template, it would render the deal/quote amount reports in HubSpot useless.

 

For point 2) - yes, as I demonstrated in my code snippet in my original post, I had figured out that I needed to use do instead of set, due to the variable scope.

 

The reason we need a custom calculation on the quote is that we quote and bill by weekly prices, and weekly billing frequency is not an available option. This introduces a serious weak point for human error, as whoever builds the quote needs to do some of the math themselves. I have upvoted and commented on an existing idea forum post requesting different billing frequency options.

View solution in original post

7 Replies 7
dennisedson
Community Manager

Hello @amandaulm 

Going to tag in @rwolupo and @ChrisBroeders  into this conversation to get some more eyes on this 😀

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
ChrisBroeders
Contributor

Hi @amandaulm ,
I had a similar sort of issue but I am not sure if this is what you are looking for. For me the issue was that my calculations were not being added to the Total value that is automatically calculated by HubSpot. 

What was happening here is that I was trying to use a HubL variable outside of scope. In my case the variable "TAXcalculatedfee" was defined inside the overarching if statement and can only be used up until the end of that if statement otherwise it will be outside of scope. 

From what you sent above it seems you might be doing the same thing?

In order for me to be able to use the "TAXcalculatedfee" outside the scope it is in (if statement), I had to create an object outside of the if statement and update the object inside the loop. I ended with something like this which ended up fixing the issue:

 

{% set obj = {TAXcalculatedfee : 0} %} 

Then changed the code from: 

{% set TAXcalculatedfee = fee.amount / 100 ) %} 
{{ TAXcalculatedfee|format_currency(LOCALE, CURRENCY) }}

To: 

{% do obj.update({TAXcalculatedfee: fee.amount / 100 }) %} 
{{ TAXcalculatedfee|format_currency(LOCALE, CURRENCY) }}

And finally, in order to use the value of "TAXcalculatedfee" in my calculation I replaced:

{% set totalminusTAX = QUOTE_TOTAL - TAXcalculatedfee %}

With: 

{% set totalminusTAX = QUOTE_TOTAL - obj.TAXcalculatedfee %}

 
I dont know if this will be helpful, but it seems to me like you need to define your desired item value as an object before you can setup the "do item.update".

Hope this is useful

Chris Broeders

Head of Operations Technology

www.prosperohub.com

PROSPEROHUB_LOGO_PRIMARY.png

amandaulm
Contributor

Hi @ChrisBroeders ,

 

I appreciate your reply - that is exactly what I'm trying to do in my own code, but I would prefer to do it with the existing Hubspot object of item. The item.amount I'm using is the existing Hubspot object and attribute for quote line items; I'm trying to stick with that because that attribute already works with the native line item discounts, overall quote subtotal, and overall total calculations. I'm hoping to avoid reinventing that wheel.

 

The do item.update lines I have in my code seem to update it as desired within the for loop's scope, as the line item totals calculate correctly, but the subtotal and total for the whole table of line items are not using those updated values. I'm trying to figure out if that's something I can fix by somehow passing the item.amount update for each line item back out of the for loop, or if something about Hubspot's built-in functions makes this impossible.

0 Upvotes
amandaulm
Contributor

@ChrisBroeders 

 

I might also be wrong about that item.amount attribute being used in SUB_TOTALS and QUOTE_TOTAL at all, because if I console log the item object after my do item.update in the sequence, it does look like those values are updating like I want them to. But then the SUB_TOTALS and QUOTE_TOTAL amounts don't change accordingly.

0 Upvotes
amandaulm
Contributor

I've had a few more frustrating rounds with HubSpot support on this, without getting much of anywhere. Their latest suggestion was to do this:

{% set QUOTE_TOTAL = template_data.quoteAssociatedObjects.lineItems|sum(attribute='amount')|float %}

which is what I've already done to update the SUB_TOTALS value, but if I use this for QUOTE_TOTAL also, we can't do any quote-level fees or discounts at all. Those are the reason I'm hoping I don't have to rebuilt the whole QUOTE_TOTAL calculation method to account for my changes.

 

Support also keeps directing me to come back here and post, but the information that I need to know is, what existing item or quote amount attribute is QUOTE_TOTAL using to calculate itself? That requires inside knowledge, as far as I can tell - it seems to be a proprietary HubSpot method that customers can't view.

 

I've tried updating every item attribute that looks like it might store those line item subtotals, as well as updating the quote SUB_TOTALS attribute, and none of them affect the QUOTE_TOTAL.

 

@dennisedson - is there a better place where I can post a question like this? I'm so out of ideas at this point that I feel like giving up.

0 Upvotes
jmclaren
Solution
HubSpot Employee

There's a lot of context to try to wrap my head around in this thread so I apologize ahead of time if I miss something specific.

Here's what I understand you are trying to do @amandaulm You want to manually display a different value on the quote page for the quote total, than what is calcualted on the back end in the quote/deal itself.

1. be aware that if the user approves this, the value that is still in the database is the one that's in the back-end. Since it displays different that means your numbers would be off in associating deals etc.

2. You were talking about scopes and looping through line items. When you are in a loop you can't use set, to update a variable outside the loop.
https://developers.hubspot.com/docs/cms/hubl/for-loops#variables-within-loops

You can update objects however using do:
https://developers.hubspot.com/docs/cms/hubl/variables-macros-syntax#variables-within-loops 

You could create an object outside of the loop, with just one parameter in it - the value you want to be your "total". Then in your loop perform whatever math you need to on it. Then display that resulting value.


Unfortunately in regards to support - you have been redirected back here because what you are trying to do is outside of what this functionality was intended for. The custom quote templates functionality was originally intended so companies could simply make quotes visually fit their brand's aesthetics.

The team in charge of this beta has seen that folks have had further customization ideas beyond the original intent for the feature, and as a result has been working on changes to make it easier for developers to expand upon what quote templates can do.
https://community.hubspot.com/t5/HubSpot-Ideas/Customize-Quote-template-appearance/idi-p/193644


What you are aiming to do is further customize the actual calculation of quotes and display something other than what is entered into the quote in the back-end. If you want official support for alternate ways of calculating quotes I'd advise submitting those ideas to the idea forum for that the quotes team can see the demand for the functionality, and officially support it instead.

Jon McLaren

Sr. CMS Developer Advocate

If my reply answered your question, please mark it as a solution, to make it easier for others to find.

View solution in original post

amandaulm
Solution
Contributor

Hi Jon. I appreciate your response.

 

Point 1) has been the deciding factor on my giving up on this functionality. Even if we could do exactly what I'm looking for with the quote template, it would render the deal/quote amount reports in HubSpot useless.

 

For point 2) - yes, as I demonstrated in my code snippet in my original post, I had figured out that I needed to use do instead of set, due to the variable scope.

 

The reason we need a custom calculation on the quote is that we quote and bill by weekly prices, and weekly billing frequency is not an available option. This introduces a serious weak point for human error, as whoever builds the quote needs to do some of the math themselves. I have upvoted and commented on an existing idea forum post requesting different billing frequency options.

View solution in original post