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

BUTTON performing QUERY with POSTGRESQL

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
functionmodulefieldsql
2 Replies
9198 Rodiniai
Portretas
Lakay lakay

Hi. im just new in Odoo, please guide me thanks

here is my scenario:

1.) I made a module name 'Shipping information' module here is my .py code

from openerp.osv import osv,fields

class si(osv.osv):

        _name='si'
        _columns ={
        'addr':fields.char('Shipping Address',size=100,required=True),
        'current':fields.boolean('Current'),
}
si()

as you can see it has 2 fields 1.) Shipping Address(char) which the user will input his address, 2.) Current (boolean), each address contains 'current' field  wherein it is with a 'button'.. if the user clicks the button it will toggle the boolean field of a certain record to 'true'.. here is my xml (just a snippet, dont worry it has no defect)

 here is the image to better appreciate : http://postimg.org/image/k0gjwlmcj/

<record model="ir.ui.view" id="view_si_tree">
        <field name="name">si.tree</field>
        <field name="model">si</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Shipping Information">
                <field name="addr" />

                <button name="btnSet" string="Set" type="object"/>
            </tree>
        </field>

    </record>

as you can see i use type='object' (or am i wrong? ) because i will call a function which contains the query, im planning to make this function and add to .py file, unfortunately im not able to do that because the function is not finish yet.. can you help me? i want that when the button is pressed it will toggle the boolean variable to 'true' of that certain id.. how can i link this to the button i have made in the xml? 

def set_current_addr(self,cr,uid,ids,name,arg,context=None):

        res={}             #is this necessary? i just saw it in other sites
        cr.execute("""UPDATE si SET current='true' where id=ids;""")

        return res        #is this necessary? i just saw it in other sites

Please guide me so that i can continue my learning in odoo.

also is 'uid' in the function there the create_id i and the 'ids' the id n openerp?

 

0
Portretas
Atmesti
Emipro Technologies Pvt. Ltd.

Hey ! I hope you got the answer from the below. If yes then please accept it. Thanks.

Portretas
Emipro Technologies Pvt. Ltd.
Best Answer

Lakay,

It's so easy !

Your method should look like,

def set_current_addr(self,cr,uid,ids,name,arg,context=None):

   self.write(cr,uid,ids,{'current':True},context=context)

   return True

Here by calling write method it is itself applying update query and your current record will be updated. It is adviceable that don't write queries, instead of that use ORM functions. Write is one of the core methods of OpenERP framework. Still if you want to do by query then below is the code.

def set_current_addr(self,cr,uid,ids,name,arg,context=None):

   cr.execute('UPDATE si SET current='true' where id=ids[0]")

   return True

No need of res = {} and return res as per your code.

Hope this helps,

 

 

 

1
Portretas
Atmesti
Emipro Technologies Pvt. Ltd.

in "ids" argument you will find the current record's id in "Array".

Lakay lakay
Autorius

Hi, itried your solution, but it gives me error ProgrammingError: column "ids" does not exist LINE 1: UPDATE si SET current='true' where id=ids[0] here is my code class si(osv.osv): def btnSet(self,cr,uid,ids,context=None): self.write(cr,uid,ids,{'current':True},context=context) cr.execute("UPDATE si SET current='true' where id=ids[0]") return True _name='si' _columns ={ 'addr':fields.char('Shipping Address',size=100,required=True), 'current':fields.boolean('Current'), } si()

Lakay lakay
Autorius

Thanks Hiren, I figured it out, so its easy to use ORM functions instead of querying! i learned it!! thanks!! this is my code def btnSet(self,cr,uid,ids,values,context=None): self.write(cr,uid,ids,{'current':'true'}) return True thanks man!!

Lakay lakay
Autorius

Thanks Hiren, I figured it out, so its easy to use ORM functions instead of querying! i learned it!! thanks!! this is my code def btnSet(self,cr,uid,ids,values,context=None): self.write(cr,uid,ids,{'current':'true'}) return True thanks man!!

Portretas
Emipro Technologies Pvt. Ltd.
Best Answer

<button name="btnSet" string="Set" type="object"/>

This button will call the method name "btnSet" of the class "si". So, you have to defind one method with the name "btnSet" as like below.

def btnSet(self, cr, uid, ids, context=None):

    #Perform your code This is comment.

    self.write(cr,uid,ids, {'current':True}, context=context) #It will write the true value into 'current' field for the record on which button is pressed.

    # you can write here more code as your requirement.

    return True #You can return anything from here.

0
Portretas
Atmesti
Lakay lakay
Autorius

thanks dude. i learned from Hiren that there is an alternative way (easier way) to modify data in database by using ORM functions such as write.. thanks for giving me solution on how to link the function in .py to button in .xml! thanks man!

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
Can you check a code of my module : filed. function
function field
Portretas
Portretas
2
kov. 15
5351
Function field issue
function field
Portretas
Portretas
1
kov. 15
4818
Purchase Order Function Field Issue
function field
Portretas
0
kov. 15
4479
Why I get this 'str' object is not callable error with my new function field? Solved
function error field
Portretas
Portretas
2
vas. 17
8536
Is there a way to connect to SQL Server Database from an odoo module? Solved
module sql connect
Portretas
Portretas
2
bal. 15
16063
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