Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to store json data with python for Odoo v13?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
v13
1 Responder
9865 Vistas
Avatar
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
Avatar
Descartar
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.

Avatar
Muhammad Yusuf
Mejor respuesta
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
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
E-Mail "Branding" in Odoo 13? How to remove Powered by / Sent by Odoo?
v13
Avatar
Avatar
Avatar
2
jun 24
6330
Error login LinkedIn v13 enterprise
v13
Avatar
Avatar
2
mar 24
1786
How we can add internal URL link(like browser) in Dashboard? Resuelto
v13
Avatar
Avatar
1
dic 22
5286
Scheduled report of an existing view
v13
Avatar
1
jun 21
3390
res.partner.bank
v13
Avatar
0
mar 21
4020
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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