Odoo Help


How to pre-fill the tax in sale order lines before adding a product?

J Miller
on 7/3/15, 3:57 AM 1,144 views

As a service company we do not use products and therefore we cannot predefine the tax in order lines which is usually defined by the product. I wrote a simple extension to set the tax on sale order line on creation:

class SaleOrderLine(osv.osv):
_inherit = 'sale.order.line'

def create(self, cr, uid, values, context=None):

        tax = self.pool.get('account.tax').browse(cr, uid, 12, context=context)
        values['tax_id'] = [[6, 0, [tax.id]]]

        return super(SaleOrderLine, self).create(cr, uid, values, context=context)

My questions are:

1.) How can I obtain the default sales tax from account configuration within the SaleOrderLine extension?

2.) At the moment the tax will be set after saving the sale order. Is there a way to pre-fill the tax field on creatrion of an order line in the frontend (Link: Add Entry)? I presume this must be done with JavaScript but I do not know how to obtain the default sales tax there and how to add a default value to the tax field.

Thanks for your help!


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 7/3/15, 4:21 AM


You just use the logic of yours into the default_get() of sale.order.line rather than create().


J Miller
On 7/3/15, 5:27 AM

Great! that answers my second question.

But how can I access the default sales tax from account configurations?

Got the answer myself:

ir_values = self.pool.get('ir.values')
taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)

see https://www.odoo.com/fr_FR/forum/help-1/question/get-default-tax-using-code-14728

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/3/15, 3:57 AM
Seen: 1144 times
Last updated: 7/3/15, 5:39 AM