Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Programmatically add products to a cart – Odoo 13

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
javascriptsalesale.orderecommercewebsite
1 Atsakyti
9637 Rodiniai
Portretas
Marcus

I have a custom module with a form. Based on the answers inside this form I’m generating order line. After user sends this form I’m creating sale order with all products from the generated order line.

So from JavaScript I’m sending an JSON with products to buy:

order_data = [{product_id: 1, amount: 10, …},{product_id: 2, …}, …];

note = ‘’;

this._rpc({

        route: '/api/create_order',

        params: { order_products: order_data, note: note }

    }).then((data) => {

        window.location = '/contactus-thank-you';

    }).catch((error) => {

        console.error(error);

    });

 

And then inside Python I’m creating sale order based on the JSON:

@http.route('/api/create_order', type='json', auth='user', website=True)

def create_order(self, **kw):

    uid = http.request.env.context.get('uid')

    partner_id = http.request.env['res.users'].search([('id','=',uid)]).partner_id.id

    

    order_products = kw.get('order_products', [])

    note = kw.get('note', '')

    order_line = []

 

    for product in order_products:

 

        amount = 0

        if 'custom_amount' in product:

            amount = product['custom_amount']

        else:

            amount = product['amount']

 

        if amount > 0:

            order_line.append(

                (0, 0, {

                    'product_id': product['product_id'],

                    'product_uom_qty': amount,

                }))

 

    order_data = {

        'name': http.request.env['ir.sequence'].with_user(SUPERUSER_ID).next_by_code('sale.order') or _('New'),

        'partner_id': partner_id,

        'order_line': order_line,

        'note': note,

    }

 

    result_insert_record = http.request.env['sale.order'].with_user(SUPERUSER_ID).create(order_data)

    return result_insert_record.id

 

But instead of generating sale order directly I need to use workflow from Odoo’s eCommerce addon. That way user can edit for example delivery address, choose payment etc. So I think I just need to put all the product inside a cart programmatically and then rest will be taken care of by Odoo built-in functionality.

But how? I’ve tried to find something inside Odoo’s source code but it is quite hard to grasp anything.

1
Portretas
Atmesti
Portretas
Paresh Wagh
Best Answer

Hi Andrzej:

The eCommerce module leverages the same models that are used by the regular Sales app i.e. sale.order, sale.order.line, etc. It creates a Quotation in the backend (with the Website tagged onto the Order) as soon as the user gets into checkout mode.

TIP: You can check this out by adding items to the shopping cart, getting into checkout mode and then checking the list of Quotations/Orders in the backend by removing the default filter criteria.

0
Portretas
Atmesti
Marcus
Autorius

I tried setting 'website_id' in the sale order but user does not see anything inside their cart. It must be something more to it.

Paresh Wagh

You're right. This needs more research. I think what you are attempting to do is to get into the workflow before the quotation is created.

Mike Cordero

Hi, Was this ever solved?

Marcus
Autorius

Hi Mike, yes I did finally solve this. Check my thread on stackoverflow

https://stackoverflow.com/questions/63034005/programmatically-add-products-to-a-cart-odoo-13/63244596#63244596

Mike Cordero

Great find.

Since I couldn't add a follow-up comment in stackoverflow, I'm placing it here:

I'm having a hard time trying to put all the pieces together to establish the following:

I've modified the website_sale.products_item template to display just the products and replaced product_price with a One2many field that I've added to the product_template model (inherited) which displays the allowed quantity available for each product.

Looking for a way to then take those quantities per product, pass them to a javascript that will determine if the selected quantities for each product exist in an allowed combination table.

My ultimate goal is to have the client select the allowed amount per product(all on the same page), click a button that will add the items to the cart (and correct quantities) in one step and take them to the cart, then finish off with the regular process.

I'm not too keen on the process of executing the javascript part from within a button in xml, and stitching the /api/create_order controller route to the sale_get_order() script above..

Any guidance in the right direction is truly appreciated.

Marcus
Autorius

It is a little bit hard to tell without any code sample.

But I would avoid using JavaScript for handling logic if possible. Especially if those limits must be enforced (customer can easily modify JS).

I would write a custom controller that you would call from JavaScript (when button is clicked) - similar to a script from my original question.

Controller then would take care of the logic and checking if given values are correct. Next it would call sale_get_order() to get or create new order. Then you could add order lines to the order generated by sale_get_order. Lastly controller can redirect customer to a cart webpage.

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

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

Registracija
Related Posts Replies Rodiniai Veikla
Javascript error Odoo 13 e-commerce/website
javascript ecommerce website 13
Portretas
Portretas
1
lapkr. 19
5363
Website Information
sale ecommerce website v9
Portretas
0
vas. 17
3718
create a Button on the home page of website
javascript ecommerce website website_sale OWL
Portretas
0
rugp. 24
2168
Pass data between controller and js
javascript ecommerce controller website eCommerce
Portretas
Portretas
1
vas. 22
3606
How to submit an element of an radio list in website? Javascript event problem.
javascript ecommerce website website_sale odoo12
Portretas
0
vas. 21
3249
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 ภาษาไทย Türkçe українська Tiếng Việt

Odoo yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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