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?
