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
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • 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

How to store json data with python for Odoo v13?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
v13
1 Atsakyti
9905 Rodiniai
Portretas
Fabian Anguiano

I wrote a simple Flask server that catches JSON data from a Post webhook and creates a sales record within Odoo v13. At the time this solution worked since my Json data only has 2 items that I needed"ItemID" and "ItemQuantity". However, now the Flask server needs to support multiple "ItemID" and "ItemQuantity". I am not sure how to best go about this.

This is the Flask server

from flask import Flask, request, abort
import xmlrpc.client


app = Flask(__name__)


# Tells the server what route and method to use
@app.route('/webhook', methods=['POST'])
def webhook():
    if request.method == 'POST':

 # Cathces the post webhook from 3D Cart and goes in, gets the product sku and the quantity. Assigns them to variables x & quantity

        content = request.json
        changetos = {'700598114683':2,
                     '763736666666':3,
                     '34232323233333':4}
        x = content[0]['OrderItemList'][0]['ItemID']
        x = changetos.get(x, x)
        quantity = content[0]['OrderItemList'][0]['ItemQuantity']
        print(content[0]['OrderItemList'][0]['ItemID'])


# Logs in to Odoo server
        url = ""
        db = "randomDB"
        username = "random"
        password = "random"

        common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
        print(common.version())

        uid = common.authenticate(db, username, password, {})
        print(uid)




 # Takes variables that were saved from the JSON post webhook and plugs into the sales record

        so_id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
            'partner_id': 10,
            'order_line': [(0, 0, {'product_id':x,'product_uom_qty': quantity})]
        }])

        return '', 200
    else:
        abort(400)


if __name__ == '__main__':
    app.run()

This is the json data that will create a sales record for the first "ItemID" and "ItemQuantity", but will not create one for the second instance of "ItemID" and "ItemQuantity".

[
{
    "InvoiceNumberPrefix": "AB-",
    "InvoiceNumber": 1000,
    "OrderID": 1,
    "CustomerID": 1,
    "OrderDate": "2016-03-17T09:52:38",
    "OrderStatusID": 1,
    "LastUpdate": "2016-03-17T09:52:38",
    "UserID": "John Doe",
    "SalesPerson": "Jane Doe",
    "ContinueURL": "http://www.some-url.com",
    "BillingFirstName": "John",
    "BillingLastName": "Doe",
    "BillingCompany": "3dcart",
    "BillingAddress": "6691 Nob Hill Rd.",
    "BillingAddress2": "Suite 100",
    "BillingCity": "Tamarac",
    "BillingState": "FL",
    "BillingZipCode": "33321",
    "BillingCountry": "US",
    "BillingPhoneNumber": "800-828-6650",
    "BillingEmail": "john@doe.com",
    "BillingPaymentMethod": "Online Credit Card",
    "BillingOnLinePayment": "true",
    "BillingPaymentMethodID": "1",
    "ShipmentList": [
      {
        "ShipmentID": 1,
        "ShipmentLastUpdate": "2016-03-17T09:52:38",
        "ShipmentBoxes": 1,
        "ShipmentInternalComment": "Some comment",
        "ShipmentOrderStatus": 4,
        "ShipmentAddress": "123 Main St.",
        "ShipmentAddress2": "Apt 123",
        "ShipmentAlias": "Someone else",
        "ShipmentCity": "Tamarac",
        "ShipmentCompany": "3dcart",
        "ShipmentCost": 12.15,
        "ShipmentCountry": "US",
        "ShipmentEmail": "someone@3dcart.com",
        "ShipmentFirstName": "Someone",
        "ShipmentLastName": "Else",
        "ShipmentMethodID": 1,
        "ShipmentMethodName": "UPS Ground",
        "ShipmentShippedDate": "2016-03-17",
        "ShipmentPhone": "800-555-1212",
        "ShipmentState": "FL",
        "ShipmentZipCode": "33319",
        "ShipmentTax": 0.00,
        "ShipmentWeight": 1.25,
        "ShipmentTrackingCode": "ABC123",
        "ShipmentUserID": "John Doe",
        "ShipmentNumber": 1,
        "ShipmentAddressTypeID": 1
      },
      {
        "ShipmentID": 2,
        "ShipmentLastUpdate": "2016-03-17T09:52:38",
        "ShipmentBoxes": 1,
        "ShipmentInternalComment": "Another comment",
        "ShipmentOrderStatus": "2",
        "ShipmentAddress": "6691 Nob Hill Rd.",
        "ShipmentAddress2": "Suite 100",
        "ShipmentAlias": "John",
        "ShipmentCity": "Tamarac",
        "ShipmentCompany": "3dcart",
        "ShipmentCost": 7.83,
        "ShipmentCountry": "US",
        "ShipmentEmail": "sjohn@doe.com",
        "ShipmentFirstName": "John",
        "ShipmentLastName": "Doe",
        "ShipmentMethodID": 2,
        "ShipmentMethodName": "USPS Priority",
        "ShipmentShippedDate": "",
        "ShipmentPhone": "800-828-6650",
        "ShipmentState": "FL",
        "ShipmentZipCode": "33321",
        "ShipmentTax": 0.00,
        "ShipmentWeight": 1.25,
        "ShipmentTrackingCode": "ABC123",
        "ShipmentUserID": "John Doe",
        "ShipmentNumber": 2,
        "ShipmentAddressTypeID": 2
      }
    ],
    "OrderItemList": [
      {
        "CatalogID": 1,
        "ItemIndexID": 1,
        "ItemID": "700598114683",
        "ItemShipmentID": 1,
        "ItemQuantity": 7,
        "ItemWarehouseID": 1,
        "ItemDescription": "Sample Product",
        "ItemUnitPrice": 9.99,
        "ItemWeight": 1.25,
        "ItemOptionPrice": 0.00,
        "ItemAdditionalField1": "3dcart internal use only",
        "ItemAdditionalField2": "3dcart internal use only",
        "ItemAdditionalField3": "3dcart internal use only",
        "ItemPageAdded": "Sample-Product.html",
        "ItemDateAdded": "2016-03-17T09:52:38",
        "ItemUnitCost": 4.57,
        "ItemUnitStock": 1,
        "ItemOptions": "Comma separated list of option IDs selected when item was added to cart (example: 123,456,789)",
        "ItemCatalogIDOptions": "Comma separated list of bundled item catalog IDs (example: 123,456,789)"
      },
      {
        "CatalogID": 1,
        "ItemIndexID": 1,
        "ItemID": "763736666666",
        "ItemShipmentID": 2,
        "ItemQuantity": 5,
        "ItemWarehouseID": 1,
        "ItemDescription": "Sample Product",
        "ItemUnitPrice": 9.99,
        "ItemWeight": 1.25,
        "ItemOptionPrice": 0.00,
        "ItemAdditionalField1": "3dcart internal use only",
        "ItemAdditionalField2": "3dcart internal use only",
        "ItemAdditionalField3": "3dcart internal use only",
        "ItemPageAdded": "Sample-Product.html",
        "ItemDateAdded": "2016-03-17T09:52:38",
        "ItemUnitCost": 1.1,
        "ItemUnitStock": 1,
        "ItemOptions": "Comma separated list of option IDs selected when item was added to cart (example: 123,456,789)",
        "ItemCatalogIDOptions": "Comma separated list of bundled item catalog IDs (example: 123,456,789)"
      }
    ],
    "OrderDiscount": 0.00,
    "SalesTax": 0.00,
    "SalesTax2": 0.00,
    "SalesTax3": 0.00,
    "OrderAmount": 39.96,
    "AffiliateCommission": 0.00,
    "TransactionList": [
      {
        "TransactionIndexID": 1,
        "OrderID": 22517,
        "TransactionID": "123XXX123",
        "TransactionDateTime": "2016-03-17T09:52:38",
        "TransactionType": "Authorize",
        "TransactionMethod": "AUTHORIZENET",
        "TransactionAmount": 10.99,
        "TransactionApproval": "SXLXXX",
        "TransactionReference": "rlsjSskdjDD/RpGDKHndihdnD",
        "TransactionGatewayID": 1,
        "TransactionCVV2": "CVVRESPONSE",
        "TransactionAVS": "AVSRESPONSE",
        "TransactionResponseText": "Transaction Response Text",
        "TransactionResponseCode": "Transaction Response Code",
        "TransactionCaptured": 1
      },
      {
        "TransactionIndexID": 1,
        "OrderID": 22517,
        "TransactionID": "123XXX123",
        "TransactionDateTime": "2016-03-17T09:52:38",
        "TransactionType": "Authorize",
        "TransactionMethod": "AUTHORIZENET",
        "TransactionAmount": 10.99,
        "TransactionApproval": "SXLXXX",
        "TransactionReference": "rlsjSskdjDD/RpGDKHndihdnD",
        "TransactionGatewayID": 1,
        "TransactionCVV2": "CVVRESPONSE",
        "TransactionAVS": "AVSRESPONSE",
        "TransactionResponseText": "Transaction Response Text",
        "TransactionResponseCode": "Transaction Response Code",
        "TransactionCaptured": 1
      }
    ],
    "CardType": "Visa",
    "CardNumber": "XXXXXXXXXXXX1111",
    "CardName": "John Doe",
    "CardExpirationMonth": "09",
    "CardExpirationYear": "2019",
    "CardIssueNumber": "XXXXXXXXXXXX1111",
    "CardStartMonth": "01",
    "CardStartYear": "1999",
    "CardAddress": "123 Anywhere St., Small Town, 33333",
    "CardVerification": "123",
    "RewardPoints": "",
    "QuestionList": 
    [
      {
        "OrderID": 1,
        "QuestionID": 1,
        "QuestionTitle": "Security Question",
        "QuestionAnswer": "Cat/Dog",
        "QuestionType": "checkbox",
        "QuestionCheckoutStep": 1,
        "QuestionSorting": 1,
        "QuestionDiscountGroup": 1
      },
      {
        "OrderID": 1,
        "QuestionID": 1,
        "QuestionTitle": "Verification Question",
        "QuestionAnswer": "Wet/Dry",
        "QuestionType": "checkbox",
        "QuestionCheckoutStep": 1,
        "QuestionSorting": 1,
        "QuestionDiscountGroup": 1
      }
    ],
    "Referer": "Google",
    "IP": "123.456.789",
    "CustomerComments": "Customer comments at checkout",
    "InternalComments": "Comments added to the order by the merchant",
    "ExternalComments": "Comments by the merchant that the customer can see"
  }
]

Not sure how to best go about this. I have tried using loops but have not had any success

1
Portretas
Atmesti
Mai Pham

Hi,

I am struggling with webhook and odoo too and surfing for any ideas. Can you tell me the reason why you have to make another server to catch the webhook and then connect to odoo to do the other stuff? Why can't we just handle the webhook directly via odoo (this is actually the thing I am trying with using odoo controllers but not successful). I don't know whether I am missing something.

Portretas
Muhammad Yusuf
Best Answer
so_id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
            'partner_id': 10, }])
lopp over items x
so_line_ids = models.execute_kw(db, uid, password, 'sale.order', 'create', [{ 'product_id':x.product_id,'product_uom_qty':x.product_uom_qty,order_id:so_id.id or so_id
}])
Not sure about the syntax but this is how it works in REST API first create SO then use it's id in SOL then it will be attached to that SO
0
Portretas
Atmesti
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
E-Mail "Branding" in Odoo 13? How to remove Powered by / Sent by Odoo?
v13
Portretas
Portretas
Portretas
2
birž. 24
6330
Error login LinkedIn v13 enterprise
v13
Portretas
Portretas
2
kov. 24
1814
How we can add internal URL link(like browser) in Dashboard? Solved
v13
Portretas
Portretas
1
gruod. 22
5337
Scheduled report of an existing view
v13
Portretas
1
birž. 21
3433
res.partner.bank
v13
Portretas
0
kov. 21
4101
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