I want to filter a many2one field with a function like this (go to the account jounal and filter by type, this type depends on witch invoice I am customer or supplier, for example):
'journal_id': fields.many2one('account.journal', 'Refund Journal',domain=[('type','=',_get_journal)])
the function is this but I dont know if this is possible:
def _get_journal(self, cr, uid, context=None):
#raise osv.except_osv(_('DEBUG'), _(str(context.keys())+str(context.values())))
obj_journal = self.pool.get('account.journal')
user_obj = self.pool.get('res.users')
if context is None:
context = {}
inv_type = context.get('type', 'out_invoice')
company_id = user_obj.browse(cr, uid, uid, context=context).company_id.id
#raise osv.except_osv(_('DEBUG'), _(str(inv_type)))
if inv_type == 'out_invoice' or inv_type == 'out_refund':
type=(inv_type == 'out_invoice') and 'sale_refund' or \
(inv_type == 'out_refund') and 'sale'
#raise osv.except_osv(_('DEBUG'), _(type))
else:
type=(inv_type == 'in_invoice') and 'purchase_refund' or \
(inv_type == 'in_refund') and 'purchase'
#type = (inv_type == 'out_invoice') and 'sale_refund' or \
# (inv_type == 'out_refund') and 'sale' or \
# (inv_type == 'in_invoice') and 'purchase_refund' or \
# (inv_type == 'in_refund') and 'purchase'
journal = obj_journal.search(cr, uid, [('type', '=', type), ('company_id','=',company_id)], limit=1, context=context)
return str(journal) and str(journal[0]) or 'False'
this show an error:
TypeError: <function _get_journal at 0xb0529f0c> is not JSON serializable