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?
Sorry i forgot to mention another thing can I edit the description field on sale order view after the onchange method executes