Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

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

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Python code get the value in a integer field by comparing two many2one fields ?

Subscribe

Get notified when there's activity on this post

This question has been flagged
2 Replies
17382 Views
Avatar
rosey

I have three fields in a table- name1, name2, cost. I already created a form for saving these fields,

And i have another form(another table)---here name1,name2 are many2one fields. When i select these two names Compare the two many2one field, its corresponding value of cost selects from the that table to this form.

How can i write a code for this?

form1 or table1

class cost()

'name1' : fields.many2one('name1.name1', required= true)

'name2' ; fields.many2one('name2.name2', required=true)

'cost' : fields.integer('Name',required=true)

cost()

eg: ram sam 1500 john sabu 43

form2 or table2

class select()

'name1' : fields.many2one('name1.name1', required= true)

'name2' ; fields.many2one('name2.name2', required=true)

'select_cost' : compare name1 and name2 select the cost from the first table1

ie, if i select ram,sam then the cost is 1500 in select_cost field or if john or sabu then cost is 43.

how can i write the code in the select_cost field?

How to use select query here?

2
Avatar
Discard
Abhishek H Menon

You have to use on_change() in the view definition of the secong program, and should give the many2one field ids as arguements. And with that arguements, you have to retrieve the cost from the first model. self.pool.get('first_model_name').search(cr,uid,[('name1','=',name1)('name2','='name2)],context=None) after running this command you will get the respective record ids and pass that id to browse that record. you will get browse_record of the first model. then you can retrieve the cost from the first table using . operator to that browse record. and return {'value':value['select_cost']=cost}

rosey
Author

Hi Abhishek, I'm new in python code. Can u please brief the code? Awaiting your reply.

rosey
Author

Please update the code it as answer.

rosey
Author

Please use the above field name, that i can easily recognize the code.

Abhishek H Menon

class first_mod(osv.osv):

rosey
Author

Hi Abhishek, please complete the code. Awaiting your reply. Its urgent for me,please

Avatar
Abhishek H Menon
Best Answer
    from osv import fields,osv
    class name(osv.osv):
        _name='name.model'
        _columns={'name':fields.char('Name',size=32)}
    name()
    class first_model(osv.osv):
        _name='first.model'
        _columns={
                  'name1':fields.many2one('name.model','Name1'),
                  'name2':fields.many2one('name.model','Name2'),
                  'cost':fields.integer('Cost')}
    first_model()

And in wizard folder,

from osv import fields,osv


    class second_model(osv.osv_memory):
        _name='second.model'
        _columns={
                  'name1':fields.many2one('name.model','Name1'),
                  'name2':fields.many2one('name.model','Name2'),
                  'select_cost':fields.integer('Select Cost')}
        def onchange_cost(self,cr,uid,ids,name1,name2,context=None):
            value={}
            if name1 and name2:
                if name1 != name2:
                    record_id=self.pool.get('first.model').search(cr,uid,[('name1','=',name1),('name2','=',name2)],context=context)
                    record=self.pool.get('first.model').browse(cr,uid,record_id[0],context=context)
                    value['select_cost']=record.cost
                else:
                    value['select_cost']=0    

            return {'value':value}
    second_model()

And for wizard view,

<record id="view_select_cost" model="ir.ui.view">
              <field name="name">second.model</field>
              <field name="model">second.model</field>

              <field name="arch" type="xml">
                <form string="Select Cost" version="7.0">

                    <group>             
                        <field name="name1"/>
                        <field name="name2"  on_change="onchange_cost(name1,name2)"/>
                        <field name="select_cost"/>
                    </group>
                </form>
              </field>
        </record>

        <record id="action_select_cost" model="ir.actions.act_window">
            <field name="name">Select Cost</field>

            <field name="res_model">second.model</field>

            <field name="view_type">form</field>
            <field name="target">new</field>
            <field name="view_mode">form</field>


        </record>

After all these process, you have to necessary action and menus inorder to display the results properly. Try this

4
Avatar
Discard
Abhishek H Menon

And in your xml view definition for the model second.model in your field , <field name="name2" on_change="onchange_cost('name1','name2')"/> and see the changes

rosey
Author

Very Thankful to you, lets try & will reply you.

rosey
Author

Hi, But cost is not selecting here. what will be the error?

Abhishek H Menon

put a print statement like print "...", record.cost below that code record=self.pool.get.... and update the module and look in your terminal console. what you are getting?

Abhishek H Menon

if you select 2 names from those many2one field, the corresponding cost will appear in the second model

rosey
Author

error is ::: record_id=self.pool.get('first.model').search(cr,uid,[('name1','=',name1),('name1','=',name2)],context=context) . AttributeError: 'NoneType' object has no attribute 'search'

Abhishek H Menon

Madam, you please do one thing. Make that second model as a wizard. then you will easily get that answer. Let me update the answer

Abhishek H Menon

Now please go for the answer, dont forget to remove the unnecessary print statements.I have given only for test purpose. Thanks

rosey
Author

Thank you very much Abhishek. Solved.

rosey
Author

If you know implement it as a postgresql query ie select query, it will be more helpful to me, to implement in other places.

rosey
Author

please implement the above code with postgresql query ie,select query. it will be more helpful to me to implement in other places.

Abhishek H Menon

Let me try Miss Rosey

Abhishek H Menon

create table name_model (pk_int_name_id int primary key,name varchar(20)); this is for creating name_model

rosey
Author

Then? What is the next step? Same as above?

Abhishek H Menon

yeah do all the tables mentioned above in the same way

Abhishek H Menon

And don't forget to refer postgreSQL study materials, the methods are same. Thanks

charlesraj

i just try this onchange function Select the first field , then select the second field call onchange function will result this warning "Access Denied

Private methods (such as _onchange_fare) cannot be called remotely."

Abhishek H Menon

change the function name from " _onchange_fare " to " onchange_fare"

charlesraj

works fine... Abishek

Avatar
AJ Schrafel Paper Corp
Best Answer

in your second module you need to put code like

    _columns = {
    '2nd_mod_field': fields.many2one('first.module', '1st_mod_field','Field Name'), 
}

and then you can access the values in 2nd_mod_field

0
Avatar
Discard
rosey
Author

i cant get your answer, Patently. Please explain.

OpenERP Vietnam

Hi Rosey, In OpenERP with the many2one field, the name (view on field many2one on form) will get from field "name" is default. If you want to get another field, you can use _rec_name = "field_name_view_on_many2one". You can refer at http://help.openerp.com/question/29746/problem-in-my-module-with-field-many2one/

Remya

HI OpenERP Vietnam, Please read the question. The requirement is differ from your answer. Please reply

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

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

Sign up
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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