Skip to Content
मेन्यू
This question has been flagged
3 Replies
14250 Views

Hi all,

I've created a masters for a terms and conditions. My-module.py

class tc_name(osv.osv): _name = 'tc.name'

def name_get(self, cr, uid, ids, context=None):
  res = []
  for code_obj in self.browse(cr, uid, ids, context=context):
      tc_name = code_obj.tc_name
      res.append((code_obj.id, tc_name))
  return res

_columns = {
            'tc_name': fields.char('Terms & Condition', size=150),
            'tc_desc': fields.text('Description')
            }

tc_name()

my_module.xml

<record id="view_tc_name_form" model="ir.ui.view">
    <field name="name">view.tc.name.form</field>
    <field name="model">tc.name</field>
    <field name="arch" type="xml">
        <form string="Terms and Conditions" version="7.0">
            <sheet>
                <group>
                    <group>
                        <field name="tc_name" strin="Terms and Condition" required="True"/>
                        <field name="tc_desc" required="True"/>
                    </group>
                </group>
            </sheet>
        </form>
    </field>
</record>

<record id="view_tc_name_tree" model="ir.ui.view">
    <field name="name">view.tc.name.tree</field>
    <field name="model">tc.name</field>
    <field name="arch" type="xml">
        <tree string="Terms and Conditions" version="7.0">
            <field name="tc_name" string="Terms and conditions"/>
        </tree>
    </field>
</record>

<record id="action_tc_name" model="ir.actions.act_window">
    <field name="name">Terms and Conditions</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">tc.name</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="view_id" ref="view_tc_name_tree"/>
</record>

<menuitem id="menu_tc_name_config" action="action_tc_name" name="Terms and Conditions" parent="base.menu_base_config" sequence="6"/>

this is working fine.

  • my_module.py

class extra_fields(osv.osv):

_inherit = "sale.order"
_columns = {
    'tc_name': fields.many2one('tc.name','Terms and Condition'),
    'tc_desc': fields.text('Description')
    }

def onchange_tc_name(self, cr, uid, ids, tc_name):
    v={}
    if tc_name:
        tc = self.pool.get('tc.name').browse(cr, uid, tc_name)
        v['tc_desc'] = tc.tc_desc
        return{'value':v}

my_module.xml

<record model="ir.ui.view" id="extra_fields_sale_order">
    <field name="name">sale.order.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form" />
    <field name="arch" type="xml">
        <group name='sale_total' position='after'>
            <group string="Terms and Conditions">
                <field name="tc_name" string="T & C" widget="selection" onchange="onchange_tc_name(tc_name, tc_desc, context)"/>
                <field name="tc_desc" string="Description"/>
            </group>
        </group>
    </field>
</record>

The master wosks fine and even it pull downs in sale order view but the onchange method does'nt work. I need the description of the terms and condition master to populate one the description field in sale order on change of terms and condition selected. Can anyone help me out?

Avatar
Discard
Author

Sorry i forgot to mention another thing can I edit the description field on sale order view after the onchange method executes

Best Answer

In your .xml file use on_change="..." attribute instead of onchange="...".

Also, follow the advise of senthil and double check your function parameters.

Regards.

post scriptum: Yes, you can change the description field. But whenever you change tc_name the on_change method will be triggered and replace the description.

Avatar
Discard
Author

Thanks a lot Rene it worked for me..!

Author

Hi Rene, I have an another issue can you please help me out in that. The link is http://help.openerp.com/question/51091/filter-on-many2many-fields

Best Answer

HI,

Try this code

def onchange_tc_name(self, cr, uid, ids, tc_name):
    v={}
    if tc_name:
        tc_name_id = self.pool.get('tc.name').search(cr, uid,[('tc_name','=',tc_name)])
        for tc_name_data in self.pool.get('tc.name').browse(cr, uid, c_name_id):
            v = { 'tc_desc': tc_name_data.tc_desc}

    return{'value':v}
Avatar
Discard

i think both v['tc_desc'] = tc.tc_desc & v = { 'tc_desc': tc.tc_desc}

Author

It doesn't work i tried both your answer but the data doesn't fetches.

I have update answer pls try it.

Best Answer

I think parameter problem

def onchange_tc_name(self, cr, uid, ids, tc_name):

See you have only one paramter in the py file

and try to pass three parameters

<field name="tc_name" string="T & C" widget="selection" on_change="onchange_tc_name(tc_name, tc_desc, context)"/>

Change it like this and check

<field name="tc_name" string="T & C" widget="selection" on_change="onchange_tc_name(tc_name)"/>

If there is problem again check ur server log post it here

Avatar
Discard
Author

this doesn't work but there is no error displayed

Related Posts Replies Views Activity
1
मार्च 15
5391
1
मार्च 15
7965
1
मार्च 15
4442
4
जून 20
27025
1
मई 17
9922