Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

Passing data from Odoo using Json

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
2 Vastaukset
5513 Näkymät
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
Hylkää
Avatar
Mahmoud El Bouyahyaoui
Paras vastaus

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
Hylkää
Austin
Tekijä

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

Regards,

Avatar
Austin
Tekijä Paras vastaus

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
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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