تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4967 أدوات العرض

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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>​

الصورة الرمزية
إهمال
الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مايو 22
2250
1
يناير 20
4331
2
نوفمبر 19
4643
1
مايو 22
3553
2
مايو 25
7757