Hi All,
How to achieve autofill some fields, for instance if you entered product code then it will automatically fill the fields.
test_prodcode_id -- entered
prodname -- autofill
desc -- autofill
price -- autofill
Thanks
PYTHON---
class test_product(osv.Model):
_name = "test.product"def name_change(self, cr, uid, ids, test_prodcode_id, prodname, desc, price, context=None):
vals = {}
_matching_ids = self.search(cr, uid, [('test_prodcode_id','=', test_prodcode_id)], context=context)
if _matching_ids:
_matching_obj = self.browse(cr, uid, _matching_ids[0], context=context)
vals = {
'value': {
'prodname': _matching_obj.prodname,
'desc': _matching_obj.desc,
'price': _matching_obj.price,
}
}
return vals
_columns = {
'test_prodcode_id': fields.many2one('test.prodcode', 'Code'),
'prodname': fields.char('Name', size=32),
'desc': fields.char('Description', size=32),
'price': fields.float('Price',),
}class test_prodcode(osv.Model):
_name = "test.prodcode"_columns = {
'name': fields.char('Product Code', size=32),
}
XML----
<record id="test_product_form_view" model="ir.ui.view">
<field name="name">test.product.form.vew</field>
<field name="model">test.product</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Product" version="7.0">
<sheet>
<field name="test_prodcode_id" on_change="name_change(test_prodcode_id)"/>
<field name="prodname"/>
<field name="desc"/>
<field name="price"/>
</sheet>
</form>
</field>
</record>
is ther anyone to point the right direction to achieve this?
Is there anyone know what module in Odoo7 to install is just like what I want to achieve? to make as my reference. Thanks
Philip, what you want can be achieved by developing the on_change behaviour of that field in the view that you want. Look for the on_change keyword in the addons folder for examples, there are myriads of them. You can read the documentation from this link: https://doc.odoo.com/trunk/server/06_misc_on_change_tips/
Thanks John, can you write simple on_change to autofill some fields, since I am a beginner in Odoo7 and this would a big help to the other Odoo beginner.
Philip, it would be more beneficial for you if you start getting acquainted with grep and search examples using the on_change keyword in addons folder, or even from Google: https://www.odoo.com/forum/help-1/question/how-to-use-on-change-function-23694, http://openerpnotes.blogspot.com/2013/01/add-on.html, http://openerpnotes.blogspot.com/2013/02/on-change-event-on-field.html. You can read more on grep from this website: http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/
One simple example that I can find in the 7.0 addons folder is in the product/product.py file. Look for onchange_type. It is a method that will set the value of factor and factor_inv if the value is 'reference'. The method is used in uom_type field in product_uom_form_view (search product/product_view.xml file for this keywoard) view. The method is applicable for product.uom model.
I have read all your post and the link as my reference but I can make it works to what I want. I have modified the above post, something like that, but instead of feeding the fields I want to get those value to my existing record.
Thanks
Hello all, Is there anyone out there, give a simple autofill field, let say product model i have code=many2one, desc=char, price=float. Then from inventory model ihave date, code, desc and price. From inventory form let say in the code field you can see all code from product model and if you entered one match then autofill the desc. and price fields. In this way beginners can understand clearly. Thanks