Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

BUTTON performing QUERY with POSTGRESQL

By
Lakay lakay
on 9/12/14, 4:59 AM 1,312 views

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?

 

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

Emipro Technologies Pvt. Ltd.
on 9/12/14, 10:48 AM
1

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,

 

 

 

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

Hiren Vora - CEO at Emipro Technologies Pvt. Ltd. India
on 9/12/14, 5:10 AM

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
on 9/14/14, 9:49 PM

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
on 9/15/14, 12:01 AM

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
on 9/15/14, 12:01 AM
0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 9/12/14, 5:09 AM

<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.

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!

Lakay lakay
on 9/15/14, 12:03 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 9/12/14, 4:59 AM
Seen: 1312 times
Last updated: 3/16/15, 8:10 AM