Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

[SOLVED] Get and Set default tax by Python command line

Subscribe

Get notified when there's activity on this post

This question has been flagged
taxtax_id
4 Replies
11723 Views
Avatar
Selverine

Hi,

First, thank you for your time.

I would like to get and set the default tax for my product.

The creation is little different than usual. I create automatically two product for each order.

I would like to get and set the tax_id for this two products. But I have not a clue...


My code:

    def create(self, cr, uid, vals, context=None):
context = context or {}
sol = self.pool.get('sale.order.line') 
if vals.get('name','/')=='/':
vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'
res = super(sale_order, self).create(cr, uid, vals, context=context)
# res is the id of the created sale order, and we create 2 lines with product_1 and product_2. Here I would like ti add tax_id: 
self.write(cr, uid, [res], {'order_line': [[0, 0, {'product_id': 1,'name': 'Service','price_unit': 50}], [0, 0, {'product_id': 4,'name': 'transport','price_unit': 15}]]})
 return res

1
Avatar
Discard
Avatar
Cyril Gaspard (GEM)
Best Answer

Hi,

call the onchange product with good order pricelist, fiscal position, date order, partner_id order .... and you will have all good values like if you will do this manually in the view.

UPDATE : code written without testing

1) just do operation in create sale.order :

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

    context = context or {}

    sol = self.pool.get('sale.order.line')

    if vals.get('name','/')=='/':

    vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'

    pricelist_id = vals.get('pricelist_id') or False

    fiscal_position_id = vals.get('fiscal_position') or False

    partner_id = vals.get('partner_id') or False

    date_order = vals.get('date_order') or False

    order_line = False

   # In onchange, I put quantity = 1 because not specified, important to calculate correctly pricelist sometimes give different price_unit depending of quantity ... (specify you real quantity by product). You can loop directly on onchange I think ...

    for product_id, qty in [(1, 1), (4, 1)]:

        onchange = sol.product_id_change(cr, uid, [], pricelist_id, product_id, qty=qty, uom=False, qty_uos=qty, uos=False, name='', partner_id=partner_id, lang=False, update_tax=True, date_order=date_order, packaging=False, fiscal_position=fiscal_position_id , flag=False, context=context)

        onchange = onchange.get('value') or False

        if onchange:

            tax_id = onchange.get('tax_id') or []

            if tax_id:

                tax_id = [[6, 0, tax_id]]

            onchange['tax_id'] = tax_id

            onchange['product_id'] = product_id

            onchange['qty'] = qty

            order_line += [(0, 0, onchange)]

    if order_line:

        vals['order_line'] += order_line

    res = super(sale_order, self).create(cr, uid, vals, context=context) 



2) to get tax (see in sol function product_id_change):

context = context or {}

lang = lang or context.get('lang', False)

if not partner_id:

     raise osv.except_osv(_('No Customer Defined!'), _('Before choosing a product,\n select a customer in the sales form.'))

partner_obj = self.pool.get('res.partner')

product_obj = self.pool.get('product.product')

context = {'lang': lang, 'partner_id': partner_id}

partner = partner_obj.browse(cr, uid, partner_id)

lang = partner.lang

context_partner = {'lang': lang, 'partner_id': partner_id}

fpos = False

if not fiscal_position:

     fpos = partner.property_account_position or False

else:

     fpos = self.pool.get('account.fiscal.position').browse(cr, uid, fiscal_position)

if update_tax: #The quantity only have changed

     result['tax_id'] = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, product_obj.taxes_id)

Bye

3
Avatar
Discard
Selverine
Author

Hi Cyril. Thank you for your help. Is it possible to call the onchange product from create? Because one is on sale.order ( create function) the other one is in sale.order.line (onchange product). So how can I find the parameters ids for onchange product? Or need I to do it in order function? Thank you. Selverine

Avatar
Selverine
Author Best Answer

Hi Cyril.

Thank you again a lot for your help.

I try the first solution but even if I don't have any erros, nothing happen.

pricelist_id,partner_id and date_order are correct.
fiscal_position_id is egual to False  (fiscal_position_id = vals.get('fiscal_position') or False)

            onchange = sol.product_id_change(cr, uid, [], pricelist_id, product_id, qty=qty, uom=False, qty_uos=5, uos=False, name='', partner_id=partner_id, lang=False, update_tax=True, date_order=date_order, packaging=False, fiscal_position=fiscal_position_id , flag=False, context=context)

            onchange = onchange.get('value') and onchange['value'].get('result') or False

            if onchange:
                tax_id = onchange.get('tax_id') or []
I have nothing for tax_id so I suppose that onchange didn't works.

Do you have any idea please?

Update3:

The output:


-> res = super(sale_order, self).create(cr, uid, vals, context=context)
(Pdb) n
IndexError: 'list index out of range'
> /opt/OpenERP/openerp/HorizonGroup/openerp/addons/sale/sale.py(519)create()
-> res = super(sale_order, self).create(cr, uid, vals, context=context)
(Pdb) print vals
{'origin': False, 'message_follower_ids': False, 'bat_sent_to_Ed': False, 'categ_ids': [[6, False, []]], 'order_line': [(0, 0, {'product_uos_qty': 1, 'name': u'Service', 'product_uom': 5, 'order_id': 168L, 'price_unit': 75.0, 'price_list': u'Service', 'delay': 7.0, 'product_packaging': False, 'product_id': 1, 'th_weight': 0.0, 'product_uos': False, 'type': u'make_to_order', 'purchase_price': 30.0, 'condition': u' ', 'tax_id': [6, 0, [2]]}), (0, 0, {'product_uos_qty': 1, 'name': u'Transport', 'product_uom': 1, 'price_unit': 1.0, 'price_list': u'Transport', 'delay': 7.0, 'product_packaging': False, 'product_id': 4, 'th_weight': 0.0, 'product_uos': False, 'type': u'make_to_order', 'purchase_price': 0.0, 'condition': u' ', 'tax_id': [6, 0, [2]]})], 'picking_policy': 'direct', 'order_policy': 'manual', 'image': '/9j/4AAQSkZJRgABAQAAAQABAAD/4QcqRXhpZgAASUkqAAgAAAAIABIBCQABAAAAAQAAABoBCQABAAAASAAAABsBCQABAAAASAAAACgBCQABAAAAAgAAADEBAgAOAAAAbgAAADIBAgAUAAAAfAAAABMCCQABAAAAAQAAAGmHBAABAAAAkAAAAN4AAABnVGh1bWIgMi4xNC4zADIwMTU6MDI6MD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1sFLtHxiIWmFPLbjrjsfKyxdHTUDz81I4bAPW/JWJZagfTaDvXEGQsdk3uijj96QfJSG7O8XI3y0o/OfRSodqB/mYbE73ZSPkV9/2oU9t+Fuv/AJvotBHQ5at1yu335NSLp8R/yP3esc/Z3jABtLSn859FGmyHj0Yu2COT3ZAsu/ajEB7OF7/Gb6KHUbUKt1xT0NMw/ecXei6S0eWwOzI7dfmFyyXETraP3esDV5dxekuZ8PnaBz0Ej4hQPsHtdpc0g9LLMVe0HMM/sx1EcN+TIx87la9X4riFbKZqueSR5B4neoFXDRMPyznHaB6g8k/E6d31ABsUovZCb6hq6dFduVp5anLtBPMbyPgaSeu5UFE1z5LWueu/x4q/8tQiDL9BECTpp2cf7Ba/Jml0sltVh+bqVi4s1t9ayCIi+gKEh3hVbnTKNZTTzVNDE+eleSbMF3Mvyt0VpIpuJ4XFiMXRydVtR/pMU9S6B2k1edpoi0uBBvp0m+4r4WcJG7iRbc4m5K9AYlgmFYiD2uhhkce9ps74jeteq9nmCTEuhfUQE8g4ED4hYWpydWMPwnBw/B9uKtRYvER2wQqbLiSdTr2POOx+K6vby0HVa+q3krVm2ZxH+Fislujo7/NR3bMZtVxirf8AWfVTDlnFG/xcR7poYnTHzeqrHSHNvYXJsCR4LlrbMtbgbE/grOZswPexUDff2YvqpcGzLD2n9/iE8nUNaB6ruzLGJu1x23j3XLsUph5uBVTi17m/DdZSKWmnqHiOGGSR7uAaCSVc1FkPL1OQXU0k5H9R/pZZ+iw+hom6aSkhhH3GAKpTZMqXm8zw0fbrPJKy4zGO40lVrlDIdXNNHU4szs9O0giHvP8AA9P+q0mNDWhrQAALADkuUW2w3C4MOj0IvHWTrKiVFS+odpPRERUkuiIiEIiIhCIiIQiIiEIiIhCIiIQiIiEL/9k=', 'order_line4': [], 'shop_id': 1, 'client_order_ref': False, 'order_line5': [], 'date_order': '2015-04-04', 'partner_id': 27, 'message_ids': False, 'fiscal_position': False, 'user_id': 1, 'sale_BAT3': [], 'payment_term': 4, 'company_id': 8, 'texte_bat': 1, 'pricelist_id': 1, 'project_id': False, 'incoterm': False, 'ecart': 0, 'section_id': False, 'link_purchase': False, 'partner_invoice_id': 27, 'description_BAT': False, 'order_line3': [], 'name': u'SO182', 'partner_shipping_id': 27, 'description_Quotation': False, 'invoice_quantity': 'order', 'devis_accept_by_client': False}
(Pdb) print order_line
[(0, 0, {'product_uos_qty': 1, 'name': u'Service', 'product_uom': 5, 'order_id': 168L, 'price_unit': 75.0, 'price_list': u'Service', 'delay': 7.0, 'product_packaging': False, 'product_id': 1, 'th_weight': 0.0, 'product_uos': False, 'type': u'make_to_order', 'purchase_price': 30.0, 'condition': u' ', 'tax_id': [6, 0, [2]]}), (0, 0, {'product_uos_qty': 1, 'name': u'Transport', 'product_uom': 1, 'price_unit': 1.0, 'price_list': u'Transport', 'delay': 7.0, 'product_packaging': False, 'product_id': 4, 'th_weight': 0.0, 'product_uos': False, 'type': u'make_to_order', 'purchase_price': 0.0, 'condition': u' ', 'tax_id': [6, 0, [2]]})]

Best regards,


Selverine


PS: name_BAT was a text field. I changed my code and now it is working better ;-)

0
Avatar
Discard
Selverine
Author

Hi Cyril. I updated my answer. Than you !

Cyril Gaspard (GEM)

hi, sorry for delay, alot of work, I updated my code, you should now enter in the condition if onchange, but in the dict 'value' you returned with pdb, what is the field 'name_BAT': u'ServiceBAT[]1' ? Type of field and value ? I think the value will give an error, stand answer. bye

Selverine
Author

Hi Cyril. I am really sorry to answer just now...some problems too :-(. I updated my answer with the new output. Thank you a lot, for your time. It is really nice ! Selverine

Cyril Gaspard (GEM)

Hi, oups, I forgot to set calculated value in vals for field order line, just add after the loop for => if order_line: vals['order_line'] = order_line, I updated my answer with this, should work now (if no tax displayed, save the sale order, and verify if taxes are displayed), bye

Selverine
Author

I updated my answer to ;-). Now I have an error: IndexError: 'list index out of range'. Selverine

Cyril Gaspard (GEM)

oups 2, tax_id should be a list of list : tax_id = [[6, 0, tax_id]], code updated.

Selverine
Author

You are my god, It works! Thank you a lot! I just changed this: vals['order_line'] = order_line to vals['order_line'] += order_line in order keep the others order_line.

Cyril Gaspard (GEM)

Hi, right for +=, good news now it works, good continuation, bye

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Create custom Group Tax with custom module Solved
tax tax_id account.tax
Avatar
Avatar
1
May 18
7550
Advance customer payment and its VAT reflection
tax
Avatar
Avatar
2
Nov 25
3897
POS Tax
tax
Avatar
Avatar
1
Jul 25
9032
Federal Unemployment Tax (FUTA) calculates at 10X in Payroll App
tax
Avatar
1
Mar 25
2944
Tax rate on shipping cost Germany/ Austria
tax
Avatar
Avatar
2
Aug 24
3604
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now