Hello nuckles,
I do have another solution to solve your problem. Let's create another boolean field to compare date range and use it on filter instead of using both date fields. You can follow the below things in the v7 coding pattern.
According to v7 pattern
'is_received_date': fields.function(is_received_date, fnct_search=_func_search_is_received_date, method=True, type='boolean', string='Is Received Late')
def _func_search_is_received_date(self, cr, uid, obj, name, args, context):
match_ids = []
query = 'SELECT id FROM account_invoice ' \
'WHERE date_received > date_doc'
cr.execute(query)
for row in cr.fetchall():
match_ids.append(row[0])
if match_ids:
return [('id', 'in', match_ids)]
else:
return [('id', '=', 0)]
def is_received_date(self, cr, uid, ids, fieldnames, args, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.date_received > line.date_doc
return res
According to Odoo v11 and v12 pattern
compare_date = fields.Boolean(compute="_compute_compare_date", store=True)
@api.depends('date_received', 'date_doc')
def _compute_compare_date(self):
for record in self:
if record.date_received and record.date_doc and record.date_received > record.date_doc:
record.compare_date = True
else:
record.compare_date = False
Add the following in your XML file.
<filter domain="[('compare_date','=', True)]" help="Received Invoice"/>
Hope this will help you. Please vote if you find a solution.
Thanks