Try this :
You add this In py:
_columns = {
'id_no' : fields.char('id no', size=64),
}
_defaults = {
'id_no': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'sequence_code'),
}
def add(self, cr, uid, ids, context):
vals = {}
vals['id_no'] = 'Pre'+ids[0]
self.create(cr, SUPERUSER_ID, vals, context)
return True
In view:
<record>
----------
<field name="id_no"/>
<button name="add" colspan="1" string="Add" type="object" />
</record>
<record id="seq_unique_id" model="ir.sequence.type">
<field name="name">my_sequence</field>
<field name="code">sequence_code</field>
</record>
<record id="seq_unique_id2" model="ir.sequence">
<field name="name">my_sequence</field>
<field name="code">sequence_code</field>
<field name="prefix">prefix</field>
<field name="padding">3</field>
</record>
Why not using the Add Item link? Make the tree view not readonly?
I mean yes add a link is a good example, but what im trying to do is generate lots of date when you click a button with predefined default values.
Check the create_period method in odoo/odoo/addons/account/account.py. It is called from a button in view_account_fiscalyear_form view (odoo/addons/account/account_view.xml)
And if you create without passing any value, it will use all default values.
Ivan thanks very good example!