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

Record create/write in Odoo8.0 new API

Subscriure's

Get notified when there's activity on this post

This question has been flagged
updatewriterecordsodoo8.0
8 Respostes
19312 Vistes
Avatar
Dr Obx

How to do it ?:

def check_code(self):

print '== Check postcode =================================================================='

code_check = self.env['post.coder'].search([('postcode','=',self.buyer_postcode)])# reading code, if code exist

it show me the code correctly, If code doesn't exist False is printed on screen. So now i would like to update record and add street name where the code is or if code not exist in database  add new record.

if code_check is False:

# this condition apparently doesn't work

    print 'Post code:', code_check.postcode

else:

    #execute(""" UPDATE post_coder SET street = %s WHERE postcode = %s""" %(self.buyer_address_1,self.buyer_postcode))

print ' Post code updated'

How using non python query add or update record in table ?


0
Avatar
Descartar
Avatar
Axel Mendoza
Best Answer

using the api

self.env['post.coder'].write(code_check, {'street': self.buyer_address_1})

or use the cursor like:

self.env.cr.execute(""" UPDATE post_coder SET street = %s WHERE postcode = %s""" %(self.buyer_address_1,self.buyer_postcode))
2
Avatar
Descartar
Dr Obx
Autor

Thank you Axel But why if statement won't work ?

Dr Obx
Autor

How can I do it in more Odoo style ? ... self.env['post.coder'].write([('postcode','=',self.buyer_postcode)]) ???

Axel Mendoza

Check the answer again to see how to do it using the api

Dr Obx
Autor

O yeah, thank you Axel :)

Dr Obx
Autor

What if I would like to update/write more than one element ? self.env['post.coder'].write(code_check, {'street1': self.buyer_address_1,'street2': self.buyer_address_2}) ??

Axel Mendoza

exactly as you put it, and if you wanna update more that one records with the same data you could do it like:
self.env['post.coder'].write([code_check, code_check1, code_check2], {'street1': self.buyer_address_1,'street2': self.buyer_address_2})

Dr Obx
Autor

Hey Axel, just to clarify, the UPDATE API command should look like this:

self.env['res.partner'].write({'name': record.buyer_full_name.title(), 'city': record.buyer_city.title(), 'street': record.buyer_address_1.title(), 'street2': record.buyer_address_2.title(), 'zip': postcode.upper(),'email': record.buyer_email.lower(), 'phone': record.buyer_phone_number})
the INSERT API command should look like this:
self.env['res.partner'].create({'name': record.buyer_full_name.title(), 'city': record.buyer_city.title(), 'street': record.buyer_address_1.title(), 'street2': record.buyer_address_2.title(), 'zip': postcode.upper(),'email': record.buyer_email.lower(), 'phone': record.buyer_phone_number})
Am I right ? What is this then:
self.env['post.coder'].write(code_check, {'street': self.buyer_address_1})
Dr Obx
Autor

As I understand

self.env[table.name].operation(what_is_this{'field': value})
and what if I will try to write something without 'what_is_this'? look below (example):
self.env['res.partner'].write({'name': record.buyer_full_name.title(), 'city': record.buyer_city.title(), 'street': record.buyer_address_1.title(), 'street2': record.buyer_address_2.title(), 'zip': postcode.upper(),'email': record.buyer_email.lower(), 'phone': record.buyer_phone_number})
Avatar
Atchuthan - Technical Consultant, Sodexis Inc
Best Answer

The result of code_check is a list of recordset.
You can use the python methods available in model using the recordset itself.

code_check.write({'street': self.buyer_address_1})
0
Avatar
Descartar
Dr Obx
Autor

Thank you Atchuthan, and it works, but if I would like to update record with more than one element i mean: self.env.cr.execute(""" UPDATE post_coder SET street = '%s' number = '%s' and something WHERE postcode = '%s'""" %(self.buyer_address_1,self.buyer_house_number,self.buyer_postcode)) I'll ask again, what if I would like to update/write more than one element ? self.env['post.coder'].write(code_check, {'number': self.buyer_address_1,'street': self.buyer_address_2,'postcode': self.buyer_postcode}) ?? I tried it that way but I'm getting an error or is doing nothing. example:

	def check_code(self):
		print '== Checking postcode ==============================================================='
		print '   Postcode check initiated ...'
		code_check = self.env['post.coder'].search([('postcode','=',self.buyer_postcode)])
		if code_check == False:
			print 'No postcode in database, writing ....'
			self.env['post.coder'].write(code_check, {'number': self.buyer_address_1,'street': self.buyer_address_2,'postcode': self.buyer_postcode})
			print 'Post code added'
		else:
			self.env.cr.execute(""" UPDATE post_coder SET street = '%s' WHERE postcode = '%s'""" %(self.buyer_address_1,self.buyer_postcode))
			print '   Post code updated:',code_check.postcode
			print '===================================================================================='
Dr Obx
Autor

So if I get as a result False (no postcode in database) i would like to add it and also if postcode is already in database, updating only street and number (this part works :)) What i've done wrong ?

Atchuthan - Technical Consultant, Sodexis Inc

code_check.write({'number': self.buyer_address_1,'street': self.buyer_address_2,'postcode': self.buyer_postcode}) You can add n number of fields to update in write method

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
Update all record
update records
Avatar
Avatar
5
de des. 15
13864
Update database field
wizard update write
Avatar
0
d’oct. 24
189
External API update / write method problem Solved
external update api write
Avatar
Avatar
2
de març 25
2811
Cannot Update missing Report
accounting update records error_updating
Avatar
Avatar
1
de set. 23
2777
write and create function Solved
function create write odoo8.0
Avatar
Avatar
Avatar
2
de juny 25
91161
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