Skip to Content
Menu
This question has been flagged
2 Replies
3899 Views

Dear all,
I am using Odoo 12 and need to print (on the sales order report) a resume of all taxes included on the sales order.
For this, I have tried to create a binary field and pass a dictionary to this field on a computed field.

What I have tried:

1. On the model:

      tax_on_lines = fields.Binary(string="Taxes Lines", compute='_check_taxes')

      def _check_taxes(self):
     for document in self:
         res = {}
         for line in document.order_line:
             tax = line.tax_id
             res.update({tax.name: tax.description})
         document.tax_on_lines = res
         print(document.tax_on_lines)

On the sales order report xml:

     <t t-foreach="doc.tax_on_lines" t-as="tax_on_lines">
         <span t-esc="tax_on_lines"/>
     </t>

This is not working (at least for the xml  - nothing is printed on the report) and I am sure the problem is on the "_check_taxes" method.

When I look to the print() method on the model, I get the following result:

     {'V01': 'Tax description 1', 'V02': 'Tax description 2', 'V05': 'Tax description 5', 'V03': 'Tax description 3'}

So, this ensures that the values are being passed to the "res" dictionary, but in some point the values are not passed to the xml.

Can anyone help me?
Basically I need to print on the sales order report, all taxes included on the sales order. Something like:

      VAT1 - VAT 10%
      VAT2 - VAT 13%
      VAT5 - VAT 23%
      VAT3 - VAT 15%

Thank you all in advance

Best regards

Paulo

Avatar
Discard
Author Best Answer

Hello everyone,

It is not the best code for sure but I solved my problem with:

On the model:

    def _check_taxes(self):
        for document in self:
             res = {}
             for line in document.order_line:
             tax = line.tax_id
             if tax:
                 res.update({tax.name: tax.description})
        if res == {}:
             document.tax_on_lines = ""
        else:
             res = sorted(res.items(), key=lambda l: l[0])
             document.tax_on_lines = [(
                 l[0] + ' - ' + l[1]
             ) for l in res]

On the xml:

      <t t-if="doc. tax_on_lines ">
           <t t-foreach="doc. tax_on_lines   " t-as=" tax_on_lines ">
                  <small><span t-esc=" tax_on_lines "/></small><br />
           </t>
     </t>

Thank you

Avatar
Discard
Best Answer

In your first solution, why don't you just iterate document and get value from it instead of creating tax_on_lines fields 
like

<t t-foreach="doc.order_line" t-as="line">
          <small>
                  <span>  <t t-esc="line.tax_id.name"/> - <t t-esc="line.tax_id.description"/> </span>
          </small>
</t>​

Avatar
Discard
Author

Hello @Ravi,

Yes. You're right.

The only problem is that I do not need to repeat the same tax already on the "resume". Each tax should only appear once and using you're approach, if I use the same tax more than once, it will appear on the resume several times as shown on the invoice lines.

Thank you once again

Related Posts Replies Views Activity
0
May 22
1371
1
Jan 20
3513
2
Nov 19
3440
1
May 22
2332
3
May 22
6210