This question has been flagged
1 Reply
2525 Views

I'm trying to extend the sale_layout module to include a total (at the moment it only has subtotal). Being a Python newbie I'm struggling. This is the error I'm getting:

QWebException: ""finaltotal" while evaluating
"p['finaltotal']"" while evaluating
"translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_saleorder_document')"

 

Here is the code, with my additions highlighted in bold:

models/sale_layout.py

def grouplines(self, ordered_lines, sortkey):
    """Return lines from a specified invoice or sale order grouped by category"""
    grouped_lines = []
    for key, valuesiter in groupby(ordered_lines, sortkey):
        group = {}
        group['category'] = key
        group['lines'] = list(v for v in valuesiter)
        group['finaltotal'] = sum(line.price_subtotal for line in group['lines'])

        if 'subtotal' in key and key.subtotal is True:
            group['subtotal'] = sum(line.price_subtotal for line in group['lines'])
        grouped_lines.append(group)

    return grouped_lines

 

views/sale_layout_category_view.xml

<template id="finaltotal_template">
    <!-- Final Total -->
    <t t-if="'subtotal' in p['category'] and p['category'].subtotal is True">
        <tr class="text-right">
            <td colspan="100">
                <strong>Total: </strong>
                <span t-esc="p['finaltotal']" t-esc-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/>
            </td>
        </tr>
    </t>
</template>

I've only made basic changes, but I cannot figure out why this isn't working. I know the calculation isn't right, I'm just trying to add the field to start with. Thanks.

Avatar
Discard
Best Answer

Try to add field 'finaltotal' in model 'sale_layout.category' similar to field 'subtotal' (with default = True).

Avatar
Discard
Author

Thank you, I knew it would be something really obvious. Adding the field to the model worked great.