0

I'm sorry for my English

I am writing a custom Qweb print report for Odoo invoices and my goal is add o.amount_untaxed + tax_amount_by_group(only positive values, excluding negative withholding); this is my code:

<t t-set="total" t-value="o.amount_untaxed"/>
<t t-foreach="o._get_tax_amount_by_group()"
   t-as="amount_by_group">
  <small> <tr>
    <td> <span t-if="amount_by_group[0] == 'Taxes'">
      <span t-esc="amount_by_group[1]"/> </span> <br></br>
    <t t-set="total" t-value="unicode(o.amount_untaxed)+amount_by_group[1]"/>
    <t t-esc="total"/>
    </td>
  </tr> </small> <br></br>
</t>

But the result is (based on actual DB records):

Subtotal $ 4,644.95
Taxes $ 557.39

Taxes 4644.95$ 557.39
Witholding 4644.95$ -167.21
Witholding 4644.95$ -46.45

My expected result need be (based on actual DB records):

Subtotal $ 4,644.95
Taxes $ 557.39

Total $ 5202.34

Total is the result of untaxed_amount + taxes (excluding withholding); I really tried many ways and I can not find the right one!

ChesuCR
  • 9,352
  • 5
  • 51
  • 114

2 Answers2

0

There is a method for tax calculation. for your total call a method from template and in that call that tax method. tax method will return with dictionary with value tax amount, subtotal and total.

fetch your required value and calculate total according to your calculation.

and return that total.

  • thanks for your answer; could you help me please with some example code about this? :) –  Sep 06 '16 at 06:34
  • @CoderX, There is a method named 'compute_all' inside 'account.tax' model. that will return {taxes, total_excluded, total_included, base}. taxes is list of dict of all tax applied in order. total_excluded is amount without tax. and total_included is amount with tax. base is total amount. just refer this method. i am sure this method will defiantly help you. – Divyang Jariwala Sep 06 '16 at 08:15
0

What about using Odoo's tax lines?

<t t-set="total" t-value="o.amount_untaxed"/>
<!-- maybe use widget monetary -->
<t t-foreach="o.tax_line" t-as="t">
  <small> <tr>
    <td>
      <t t-if="t.amount &gt;= 0.0">
        <p t-esc="t.amount"/>
        <t t-set="total" t-value="total + t.amount"/>
      </t>
    </td>
    <td><t t-esc="total"/></td>
  </tr> </small> <br></br>
</t>
CZoellner
  • 13,553
  • 3
  • 25
  • 38