This question has been flagged
2 Replies
3587 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.

Avatar
Discard
Author Best Answer

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).



        Avatar
        Discard
        Best Answer

        Have you found a solution ?

        Avatar
        Discard