from openerp.osv import osv, fields
from datetime import dateclass archive_storage(osv.Model):
_name = 'archive.storage'
_columns={
'item_name': fields.char('Name'),
'storage_device': fields.many2one('archive.storage.type','Storage Device', required=True),
'name': fields.char('Accession Number', required=True),
'accession_date': fields.datetime('Accession Date', required=True),
'barcode_number': fields.char('Barcode NO'),
'properties': fields.text('Properties'),
'company': fields.char('Company'),
# 'description': fields.text('Description'),
'disk_quantity': fields.integer('Disk Quantity'),'is_issued': fields.boolean('Is Issued'),
'issued_to': fields.many2one('hr.employee', 'Issued To'),
'issue_date': fields.datetime('Issue Date'),
'return_date': fields.datetime('Return Date'),
'shelf_no': fields.char('Shelf No'),
'row_no': fields.char('Row No'),
'tray_no': fields.char('Tray No'),
'robotic': fields.selection([('na', 'N/A'),('in robotic', 'In Robotic'), ('out of robotic', 'Out of Robotic')],'Robotic'),'category': fields.many2one('archive.storage.category','Category', required=True),
'remark': fields.char('Remarks'),
'condition': fields.selection([('fine','Fine'),('damage','Damage'), ('lost', 'Lost')],'Condition'),
'tape_type': fields.many2one('archive.tape.type', 'Tape Type', required=True),
'duration': fields.char('Duration'),'submitted_by': fields.many2one('hr.employee','Submitted By'),
'storage_media_content_id': fields.one2many('archive.storage.media.content', 's_m_c_id', 'Master Program'),
'entry_by': fields.many2one('hr.employee', 'Entry By'),
}_defaults = {
'entry_by': lambda s, cr, uid, c: uid,
'accession_date': fields.datetime.now,
'disk_quantity': 1,
}_sql_constraints = [
('name_unique', 'unique(name)', 'Accession Numer already exists!')
]
def onchange_storage_device(self, cr, uid, ids, storage_device, context=None):
if storage_device:
storage_name = self.pool.get('archive.storage.type').browse(cr, uid, storage_device, context=context)
return {'value': {'name':self.pool.get('ir.sequence').get(cr, uid, storage_name.name)}}
# return {'value': {'name':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'bank_pay_voucher')}}
return {'value': {}}
def onchange_reference_storage(self, cr, uid, ids, name, context):
ctx = dict(context)
ctx.update({'storage_source': 'asdfs'})
return{
'view_type': 'form',
'view_mode': 'form',
'res_model': 'archive.media.content',
'context': ctx,
'type': 'ir.actions.act_window',
'nodestroy':False,
'target': 'inline',
}
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
You cannot return an action from onchange method. Onchage only returns value, domain and warning only.
You can read documentation about What should onchange method do and return? and onchange method.
To return an action from method, the method should be called from button of type object. To fill the values of the fields in the form which you want to open, you have to pass the fields and their values in context as given in below example:
if context is None:
context = {}
ctx = context.copy()
ctx.update({'default_storage_source': 'asdfs'})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'archive.media.content',
'context': ctx,
'type': 'ir.actions.act_window',
'nodestroy':False,
'target': 'inline',
'context': ctx,
}
You can find examples in addons as well. Return action with default values.
In Sales module, Quotations tab under Sales after selecting Customer from dropdown eg(Agrolait) when create or edite option is select from Contract/Analytic filed, the new pop up form sets customer "Agrolait" autometically. How can I do this? Plz help
Rokon, as Sudhir has mentioned, you cannot call an action from on_change method. Assuming that you code it as Sudhir had mentioned, you can pass 'default_XXXX' key-value in the context where XXXX is the field name and the value is the value that you wish to be displayed by default in the called view.
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