Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Record create/write in Odoo8.0 new API

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
updatewriterecordsodoo8.0
8 Réponses
19306 Vues
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
Ignorer
Avatar
Axel Mendoza
Meilleure réponse

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
Ignorer
Dr Obx
Auteur

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

Dr Obx
Auteur

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
Auteur

O yeah, thank you Axel :)

Dr Obx
Auteur

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
Auteur

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
Auteur

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
Meilleure réponse

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
Ignorer
Dr Obx
Auteur

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
Auteur

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

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Update all record
update records
Avatar
Avatar
5
déc. 15
13860
Update database field
wizard update write
Avatar
0
oct. 24
189
External API update / write method problem Résolu
external update api write
Avatar
Avatar
2
mars 25
2808
Cannot Update missing Report
accounting update records error_updating
Avatar
Avatar
1
sept. 23
2774
write and create function Résolu
function create write odoo8.0
Avatar
Avatar
Avatar
2
juin 25
91156
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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