Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[V9] How do I show all taxes on a Sales Order? Connecting sale.order and account.tax??

By
TK Fontaine
on 12/3/15, 10:57 AM 512 views

Hi,

I want to show all taxes on sale order.

So i have to connections :

  1. sale.order to sale.order.line : a One2many, with inverse_name = order_id

  2. sale.order.line to account.tax : a Many2many.

My question is how to connect sale.order with account.tax?

Thank you.

0
TK Fontaine
On 2/26/16, 10:34 AM

Hello YannCopp,


Yes I finally found a solution :

In python, I inherit sale.order :

class Sale_order(models.Model):

_inherit = 'sale.order'

tabTaxes = fields.Many2many('account.tax', compute='_compute_my_taxe', string='tabTaxes')

@api.multi

def _compute_my_taxe(self):

maliste = []

for obj in self.order_line:

for taxe in obj.tax_id:

maliste.append(taxe.id)

self.tabTaxes = list(maliste)

@api.one

def get_amount(self, taxeNom):

total = 0

for ligne in self.order_line:

for taxe in ligne.tax_id:

if (taxeNom == taxe.name):

try:

total += ligne.price_reduce * (taxe.amount / 100.)

except:

total += 0

return "{0:.2f}".format(total)


  •   _compute_my_taxe : to get list of my taxes.

  • get_amount : to get amount of that taxes.


Then in my report xml :

<t t-foreach="doc.tabTaxes" t-as="v">

<tr>

<td>

<span t-esc="v.name"/>

</td>

<td>

<span t-esc="doc.get_amount(v.name)[0]"/>

</td>

</tr>

</t>


But I think I'll try using dictionnaries, like I did here : http://stackoverflow.com/questions/34122439/odooqwebdictionary-foreach-print-key-and-value/35655404

And if I wouldn't able to connect sale.order.line with account_tax, I'll use request SQL :

SELECT *

FROM sale_order_line a

,account_tax_sale_order_line_rel b

,account_tax c

WHERE a.id = b.sale_order_line_id

AND b.account_tax_id = c.id


And I'll adapt my request with :

@api.one

def get_taxes(self, myparameter):

self._cr.execute("""<MYREQUEST_WITH_PARAMETER>=%s""", (myparameter,))

_res = self._cr.dictfetchall()

if not _res: #To control if it's not empty

return #???

return _res[0]

Where
        • myparameter : it will be my ID of sale.order  

        • MYREQUEST_WITH_PARAMETER : it will be my request

        • _res[0] : it will return a dictionary


        But I don't know yet how to handle empty result (if not _res).



        0
        YannCopp
        On 2/11/16, 5:50 AM

        Have you found a solution ?

        Your Answer

        Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

        About This Community

        This community is for professionals and enthusiasts of our products and services. Read Guidelines

        Question tools

        1 follower(s)

        Stats

        Asked: 12/3/15, 10:57 AM
        Seen: 512 times
        Last updated: 2/26/16, 10:36 AM