Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

DISPLAYING THE SAME ORDER OF KEY WHICH HAVE IN MY LIST OF DICTIONARY KEYS IN MY OUTPUT

Subscriure's

Get notified when there's activity on this post

This question has been flagged
pythonpython2.7openerp7python3odoo
4 Respostes
6836 Vistes
Avatar
Dasadiya Chaitanya

I am using python 2.7.X version and I need to display my result of list of dictionary in key order same as in my output


CREATE THE LIST OF DICTIONARY : 

 

for acc_data in acc_pool.browse(cr,uid,acc_ids_in):

for line in acc_data.invoice_line:

c+=1

lst_data2.append({

'SupplierName':acc_data.partner_id.name or '',

'SupplierBRN':acc_data.partner_id.com_reg_no1 or '',

'InvoiceDate':acc_data.date_invoice or '',

'InvoiceNumber':acc_data.number or '',

'ImportDeclarationNo':'',

'LineNumber':c,

'ProductDescription':line.product_id.name or '',

'PurchaseValueMYR':line.price_unit or 0.00,

'GSTValueMYR':'',

'TaxCode':line.invoice_line_tax_id.name or '',

'FCYCode':'',

'PurchaseFCY':'',

'GSTFCY':'',

})


RESULT ::

my result displaying from the ubuntu terminal

lst_data2 ==========>>>lst_data2 [{'ProductDescription': u'Ink Cartridge', 'SupplierBRN': '', 'ImportDeclarationNo': '', 'GSTValueMYR': '', 'SupplierName': u'Vicking Direct', 'GSTFCY': '', 'TaxCode': u'Purchase Tax 15.00%', 'InvoiceDate': '2015-03-24', 'FCYCode': '', 'PurchaseFCY': '', 'PurchaseValueMYR': 58.0, 'LineNumber': 1, 'InvoiceNumber': u'EXJ/2015/002'}, {'ProductDescription': u'Toner Cartridge', 'SupplierBRN': '', 'ImportDeclarationNo': '', 'GSTValueMYR': '', 'SupplierName': u'Vicking Direct', 'GSTFCY': '', 'TaxCode': u'OTAX X', 'InvoiceDate': '2015-03-24', 'FCYCode': '', 'PurchaseFCY': '', 'PurchaseValueMYR': 65.0, 'LineNumber': 2, 'InvoiceNumber': u'EXJ/2015/002'}]

hear u can easily see my key of order is different from in my result

My Question is that i need to set the all the keys from same as created in list of dictionary above from the list.

How can I set the same order of list of keys from in my result.??





0
Avatar
Descartar
Mansi Kariya (mka)

use ordered dict. instead of regular dict. , visit this link to know use of order dict, http://pymotw.com/2/collections/ordereddict.html

Dasadiya Chaitanya
Autor

@Mansi Kariya I have resolved that one from my side Be a Coooool ..... :) Thanks For Your Comment

Avatar
Dasadiya Chaitanya
Autor Best Answer

Solution from the Above Question...

Just need to import the Following Python  Library for the code

from collections import OrderedDict

for acc_data in acc_pool.browse(cr,uid,acc_ids_in):

c=0

      for line in acc_data.invoice_line:

          if line.invoice_line_tax_id:

              c+=1

              lst_data2.append(OrderedDict([

                  ('SupplierName',acc_data.partner_id.name or ''),

                  ('InvoiceNumber',acc_data.number or ''),

                  ('ImportDeclarationNo',''),

                  ('LineNumber',c),

                  ('ProductDescription',line.product_id.name or ''),

                  ('PurchaseValueMYR',line.price_unit or 0.00),

                  ('GSTValueMYR',''),

                  ('TaxCode',line.invoice_line_tax_id.name or ''),

                  ('FCYCode',''),

                  ('PurchaseFCY',''),

                  ('GSTFCY',''),

                  ]))

OrderedDict is a dictionary subclass that remembers the order in which its contents are added.

I my case the OrderedDict is the part of the python Collection Type Which is used to set the Order of the keys from the dictionary.


1
Avatar
Descartar
Avatar
Deepa Venkatesh
Best Answer

A built in function "itemgetter" exists to sort/order a Dictionary by specifying its item-key

Example:

list_to_be_sorted = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]

from operator import itemgetter

newlist = sorted(list_to_be_sorted, key=itemgetter('name'))

0
Avatar
Descartar
Dasadiya Chaitanya
Autor

@deep I doen't want to sort the keys of the dictionary I resolved that one from my side see below answer Thanks for your reply

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
call attributes to an abstractmodel
python python2.7 odoo
Avatar
0
de gen. 20
4455
Declaration of a field - Import / Export CSV
python python2.7 odoo
Avatar
0
de juny 19
4210
How to set value in field order line while selecting a value in drop downlist
python openerp7 odoo
Avatar
0
de març 15
4664
[SOLVED] How to Hide or Delete Trash Icon in One2many field Solved
python python2.7 odoo odoo10
Avatar
Avatar
2
d’ag. 25
12987
Odoo 14 - Send Email Contact Form URL Solved
python python3 odoo v14
Avatar
1
de març 23
3405
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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