Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4982 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 22
2257
1
thg 1 20
4342
2
thg 11 19
4650
1
thg 5 22
3557
2
thg 5 25
7778