Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

[Odoo 10]How to Migrate sql injection to ORM (self.env) to update another model?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
orminjectionodoo10self.write
1 Atsakyti
8080 Rodiniai
Portretas
FEDERICO LEONI

Now that I've migrated all my python stuff on a module under Odoo I would like to clean a bit more my code starting to pull out all the lines that are writing to others models using self.env.cr.execute, not secure as a native self.write.

I' ve read the docs and I' ve seen there is a way to call another recordset using self.env.context but I did not find a clear solution to write from a model to another.

For example in a model A I need to write in model B with

sql_record_cst = 'INSERT INTO modelB (curr_day, ord_proc) values(%s, 1)'
self.env.cr.execute(sql_record_cst,[self.fieldinmodelA])
self.env.cr.commit()

What should be the equivalent solution using ORM?
First thing of, I should change the target model, then I should be able to change the value of the field with a simple self.field=value or self.write({'fieldA' : value,  'fieldB' : value}).

What I' ve tried:

(in pos.config)
if self.sequence_number == 1:
   self.env.cr.execute(sql_test_session,[str(self.start_at[0:10]+'%')])
   curr_day = self.env.cr.fetchone()
   if curr_day is None:
       today_d = str(self.start_at[0:10])
       self.env['divina.custos'].create({'curr_day':today_d,'ord_proc':1}

But I get the error:

File "/odoo_dv/odoo_dv-server/addons/point_of_sale/models/pos_config.py", line 256, in open_session_cb 'config_id': self.id File "/odoo_dv/odoo_dv-server/addons/point_of_sale/models/pos_session.py", line 196, in create res.action_pos_session_open() File "/odoo_dv/odoo_dv-server/addons/point_of_sale/models/pos_session.py", line 222, in action_pos_session_open session.write(values) File "/odoo_dv/odoo_dv-server/odoo/models.py", line 3550, in write self._write(old_vals) File "/odoo_dv/odoo_dv-server/odoo/models.py", line 3758, in _write self.recompute() File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5287, in recompute vals = rec._convert_to_write({n: rec[n] for n in ns}) File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5287, in <dictcomp> vals = rec._convert_to_write({n: rec[n] for n in ns}) File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5186, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/odoo_dv/odoo_dv-server/odoo/fields.py", line 872, in __get__ value = record._cache[self] File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5534, in __getitem__ value = self._recs.env.cache[field][self._recs.id]
KeyError: 3

 And if I try to force the field date (test purpouse) with

self.env['divina.custos'].create({'curr_day':'2017-02-21 00:00:00','ord_proc':1})

I get another error

File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5534, in __getitem__ value = self._recs.env.cache[field][self._recs.id]KeyError: 4
So I think I' m on the right path, I just need to learn the correct  syntax. 
Please note that 
self.env[model.name'].search or self.env['model.name'].browse

works juts fine.

0
Portretas
Atmesti
Portretas
Pawan
Best Answer

Federico,

Here are the some of thing which might interest you:

  •  For getting the link/access to other model we use :
    self.env['model.name'] (in new api)
    self.pool.get('model.name') ('in old api)

  • from model A, if you want to create record in model B use:
    self.env['b'].create({'key1':'val','key2':val})

  • from model A, if you want to update some field of record 'x' in model B:
    self.env['b'].write(x, {'key1':'val','key2':val})

Hope it helps!!

1
Portretas
Atmesti
FEDERICO LEONI
Autorius

Yeah, helped a lot, even if I still have some difficult to understand the syntax like

today_d = str(self.start_at[0:10])

self.env['divina.custos'].create({'curr_day':today_d,'ord_proc':1}

that is giving error. But I' m almost there!

I' ve updated my OP with one more little piece of code.

Pawan

What error are you getting?

FEDERICO LEONI
Autorius

Is on the OP, the most common is

File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5186, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/odoo_dv/odoo_dv-server/odoo/fields.py", line 872, in __get__ value = record._cache[self] File "/odoo_dv/odoo_dv-server/odoo/models.py", line 5534, in __getitem__ value = self._recs.env.cache[field][self._recs.id]

KeyError: 3

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

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

Registracija
Related Posts Replies Rodiniai Veikla
[odoo10]weird issue with self.write
orm odoo10 self.write
Portretas
0
kov. 17
3928
[odoo10] self.env.search_read find a field, simple search does not. Solved
orm odoo10 self.env.search
Portretas
Portretas
1
kov. 17
12660
[Odoo 10] .write() stop working and rise error value = self._recs.env.cache[field][self._recs.id] Solved
python records odoo10 self.write
Portretas
Portretas
Portretas
5
liep. 20
9830
raise ValueError(“Expected singleton: %s” % self) when return more than one record Solved
orm refund python2.7 odoo10
Portretas
Portretas
1
gruod. 19
6648
[SOLVED][Odoo 10] self.env[].search: how to return multiple field in a list? Solved
python orm search self odoo10
Portretas
Portretas
5
rugs. 20
63819
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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