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
    Real Estate
    • Real Estate Agency
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consulting
    • Accounting Firm
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Shoe Maker
    • Serveis de neteja
    • HVAC Services
    Others
    • 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

Append data - what I'm doing wrong ?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
pythonprogrammingodoo8.0
3 Respostes
10272 Vistes
Avatar
Dr Obx

Browsing data: - gathering product_id and qty in selected period of time (last 6 months) in location 'production'

  for obj in self.browse(cr, uid, ids):

days = obj.nod

weeks = obj.now

months = obj.nom

cr.execute(""" select product_id, sum(qty) from stock_quant where write_date ::date>=to_date('%s', 'YYYY-MM-DD') and

write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id =%s group by product_id;""" %(obj.st_date, obj.en_date, obj.location_id.id))

toty = cr.fetchall()

Browsing data and appending in_stock: -  gathering qty for product in other locations except 'production'

for prod in toty:

cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(int(prod[0])))

in_stock = cr.fetchall()

tot_qty.append([prod[0], prod[1], in_stock[0][0]])

Browsing again and appending lmsq to the existing one: - gathering qty in selected period of time (last 1 month) in location 'production'

for prod in toty:

cr.execute(""" select sum(qty) from stock_quant where product_id = %s and write_date ::date>=to_date('%s', 'YYYY-MM-DD') and

write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id = 7;""" %(int(prod[0]), obj.mt_date, obj.en_date))

lmsq = cr.fetchall()

print 'LMSQ ',lmsq

# joining lists

print 'PROD ',tot_qty, prod

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0]) 

What I'm doing wrong ?

ERROR:

File "/usr/lib/python2.7/dist-packages/openerp/addons/iProdLoc/iprodloc.py", line 124, in moves_get

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0])

TypeError: append() takes exactly one argument (2 given)

0
Avatar
Descartar
Avatar
Pawan
Best Answer

Rob,
Your way of appending Imsq to the already creating list is not correct.

As you already have a list created after creating in_stock, and then you are trying to add imsq to that samelist for that same [product, qty, in_stock] combination which will not work like the way you are trying to do it....

Keep both the fetchings under one loop only:

for prod in toty:

    Browsing data and appending in_stock: -  gathering qty for product in other locations except 'production'

    cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(int(prod[0])))

    in_stock = cr.fetchall()

    Browsing again and appending lmsq to the existing one: - gathering qty in selected period of time (last 1 month) in location 'production'

    cr.execute(""" select sum(qty) from stock_quant where product_id = %s and write_date ::date>=to_date('%s', 'YYYY-MM-DD') and write_date ::date<= to_date('%s', 'YYYY-MM-DD') and location_id = 7;""" %(int(prod[0]), obj.mt_date, obj.en_date))

    lmsq = cr.fetchall() 

    #Now finally after retrieving all data, form a list and append to tot_qty..

    tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0])

HOPE IT HELPS ;)

0
Avatar
Descartar
Dr Obx
Autor

Hehehe Hi Pawan, Already sorted it. It works beautifully :) However, I have a question for you my friend. Once I create a list of products and I would like to put it into email. Would you help me with it ? Its easy if I'm adding only one product and sending email but I can't make it work for more than one ....

Dr Obx
Autor

Or how to add data from another object. For example, stock_check is creating a list then list is passed to product_data. How can I get those data and use it in email ? Browse product_data, create another list inside the def mailing .... ?

Pawan

Rob, you can use current object field only to loop on in an email template, as template works on one object at a time, like if you are having any one2many or many2many then you can use
  % for row in object.[one2many/many2one FIELD]:
 ${row.[FIELD] or ""}
 ${row.[FIELD] or ''}
 ${object.[FIELD] or ''}
 %endfor
This will print all the records from the [one2many/many2one FIELD] under that object...
OTHERWISE
You can format your string for body of email at your logic(.py) only and then replace the templates body with your string before sending
Regards!

Avatar
Swapnesh Shah
Best Answer

Hello,

Please use 

tot_qty.append([prod[0], prod[1], in_stock[0][0], lmsq[0][0]]) 

instead of 

tot_qty.append([prod[0], prod[1], in_stock[0][0]], lmsq[0][0]) 

Thanks

0
Avatar
Descartar
Dr Obx
Autor

Problem solved :)

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
Evaluation of python expression Solved
python odoo8.0
Avatar
Avatar
1
de jul. 17
10674
create a getter for odoo 8 Solved
python odoo8.0
Avatar
Avatar
2
de jul. 17
4547
recuperate fields of budget lines
python odoo8.0
Avatar
0
d’ag. 16
3660
Using Blob to save in postgres via odoo
python odoo8.0
Avatar
Avatar
1
de jul. 16
5723
How to add auto refreshing for hr_attendance in odoo?
python odoo8.0
Avatar
0
de juny 16
3704
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