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

How can i write update query in a function?

By
samba
on 7/20/14, 1:46 PM 1,031 views

In the below fuction I want to update  "account_bank_statement" table field balance_end_real with the vale balance_end. i.e "update account.bank.statement set balance_end_real=balance_end where id=ids"

 

"def _compute_difference(self, cr, uid, ids, fieldnames, args, context=None):
        result =  dict.fromkeys(ids, 0.0)

        for obj in self.browse(cr, uid, ids, context=context):
            
            result[obj.id] = obj.balance_end_real - obj.balance_end

        return result  "

 

1

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 7/21/14, 9:52 AM

It seems that balance_end_real field already in the same model (or inherited) with the method you defined. In that case you don't need to use update sql manually, just use write method.

self.write(cr, uid, ids, {'balance_end_real': obj.balance_end}, context=context)

 

Thank you very much. This is the best answer

samba
on 7/21/14, 10:19 AM
2

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 7/21/14, 8:41 AM

Hi,

You can use "cr.execute" to update record based on id. Refer the following example:

cr.execute('update account_period set state=%s where id=%s', (mode, id))

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 7/21/14, 6:10 AM

Use "cr.execute" and update directly using sql update statement...

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

1 follower(s)

Stats

Asked: 7/20/14, 1:46 PM
Seen: 1031 times
Last updated: 3/16/15, 8:10 AM