Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

Passing data from Odoo using Json

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
2 Antworten
5507 Ansichten
Avatar
Austin

Hi, 

We are developing a module for Odoo 10 that sends data to a fiscal device using POST method. The fiscal device has an api and for the invoice, the following is the json.dump;

payload_tuples = json.dumps({
"invoiceType": 0,
"transactionType": 0,
"cashier": "Benjamin",
"TraderSystemInvoiceNumber": "test0123",
"buyer": {
"buyerName": "Buyer Name",
"pinOfBuyer": "Buyers Pin",
"buyerAddress": "Buyers Address",
"buyerPhone": "Buyers Phone"
},
"items": [
{
"name": "test",
"quantity": 1.0,
"unitPrice": 1.0
 
}
],
"payment": [
{
"amount": 1,
"paymentType": "Cash"
}
],
"lines": [
{
"lineType": "Text",
"alignment": "bold center",
"format": "Bold",
"value": "Thank you!!"
}
]
})


For this case, we wish to match data from the linvoice lines as follows;

In the items part i.e. 

"items": [
{
"name": "test",
"quantity": 1.0,
"unitPrice": 1.0
 
}
],


I wish that my module gets figures for  the following "name":  from  line.name           ; "quantity": from  line.quantity                AND    "unitPrice":  from   line.price_unit .   fields that are in the invoice lines.


I am using Odoo 10 CE hosted on a ubuntu 16 server.


Kindly assist.

Regards.
 

0
Avatar
Verwerfen
Avatar
Mahmoud El Bouyahyaoui
Beste Antwort

In order to match data from the invoice lines to the payload for the fiscal device, you can use the Odoo ORM (Object-Relational Mapping) to query the invoice lines and retrieve the desired fields. Here's an example of how you can do this in your module:

invoice_lines = self.env['account.invoice.line'].search([('invoice_id', '=', invoice.id)])
items = []
for line in invoice_lines:
    item = {
        'name': line.name,
        'quantity': line.quantity,
        'unitPrice': line.price_unit
    }
    items.append(item)

payload = {
    'invoiceType': 0,
    'transactionType': 0,
    'cashier': "Benjamin",
    'TraderSystemInvoiceNumber': "test0123",
    'buyer': {
        'buyerName': "Buyer Name",
        'pinOfBuyer': "Buyers Pin",
        'buyerAddress': "Buyers Address",
        'buyerPhone': "Buyers Phone"
    },
    'items': items,
    'payment': [
        {
            'amount': 1,
            'paymentType': "Cash"
        }
    ],
    'lines': [
        {
            'lineType': "Text",
            'alignment': "bold center",
            'format': "Bold",
            'value': "Thank you!!"
        }
    ]
}

In this example, we first query the invoice lines using the search method of the account.invoice.line model, passing the invoice_id as a filter. Then, we iterate over the invoice lines, creating an item dictionary for each line that contains the name, quantity and unitPrice fields, and append it to the items list. Finally, we include the items list in the payload dictionary.

Please keep in mind that this is just an example and you may need to adapt it to your specific use case. Also you will need to import the json library at the beginning of the file.

Also, it's important to test the changes before applying them in production as it may have side effects on other parts of the system.

0
Avatar
Verwerfen
Austin
Autor

Hi Mahmoud,
Thank you for your reply. I used your suggestions and wish to share my code / module with you.

Regards,

Avatar
Austin
Autor Beste Antwort

Hi, 

Did,



for rec in self:
#Get Token Method
if get_url:
if get_url and pin :
items = []
for line in rec.invoice_line_ids:
invoice_line = {'ID':line\.id,'DESC':line\.name,'TAXCODE':tax\.name,'QTY':line\.quantity,'AMT':line\.price_unit,'line_total':line\.price_subtotal\}
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ items\.append\(invoice_line\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ items\ =\ json\.dumps\(items\)


 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ cashier\ =\ self\.user_id\.name
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tsin\ =\ self\.number
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ buyername\ =\ self\.partner_id\.name
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ pinofbuyer\ =\ self\.partner_id\.vat
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ buyeradd\ =\ self\.partner_id\.city
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ buyerphone\ =\ self\.partner_id\.phone 
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ invoice_lines\ =\ self\.env\['account\.invoice\.line'\]\.search\(\[\('invoice_id',\ '=',\ invoice.id)])
items = []
for line in invoice_lines:
item = {
'name': line.name,
'quantity': line.quantity,
'unitPrice': line.price_unit
}
items.append(item)
payload_tuples = json.dumps({
"invoiceType": 0,
"transactionType": 0,
"cashier": cashier,
"TraderSystemInvoiceNumber": tsin,
"buyer": {
"buyerName": buyername,
"pinOfBuyer": pinofbuyer,
"buyerAddress": buyeradd,
"buyerPhone": buyerphone
},
"items": items,
"payment": [
{
"amount": 1,
"paymentType": "Cash"
}
],
"lines": [
{
"lineType": "Text",
"alignment": "bold center",
"format": "Bold",
"value": "Thank you!!"
}
]
})




Still cannot get it to work.  Kindly check and see where i went wrong.


Regards,


0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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