diff --git a/account_move_fiscal_month/models/account_move.py b/account_move_fiscal_month/models/account_move.py index 297032736..fd1f9801b 100644 --- a/account_move_fiscal_month/models/account_move.py +++ b/account_move_fiscal_month/models/account_move.py @@ -30,6 +30,8 @@ class AccountMove(models.Model): date_range_domain = [('name', operator, value)] date_ranges = self.env['date.range'].search(date_range_domain) + if not date_ranges: + return [('id', '=', False)] domain = [] for date_range in date_ranges: domain = expression.OR([domain, [ diff --git a/account_move_fiscal_month/tests/test_account_move_fiscal_month.py b/account_move_fiscal_month/tests/test_account_move_fiscal_month.py index c95c2f0c7..4d0d411ec 100644 --- a/account_move_fiscal_month/tests/test_account_move_fiscal_month.py +++ b/account_move_fiscal_month/tests/test_account_move_fiscal_month.py @@ -154,3 +154,10 @@ class TestAccountMoveFiscalMonth(TransactionCase): move_march_2017 not in moves, move_jan_2018 not in moves, ])) + # Search non existing month + moves = self.AccountMoveObj.search([ + ('date_range_fm_id', 'ilike', '2016'), + ]) + self.assertFalse( + moves + ) diff --git a/account_move_fiscal_year/models/account_move.py b/account_move_fiscal_year/models/account_move.py index eba8c0e38..28e9516ea 100644 --- a/account_move_fiscal_year/models/account_move.py +++ b/account_move_fiscal_year/models/account_move.py @@ -40,6 +40,9 @@ class AccountMove(models.Model): date_range_domain.append(('type_id', '=', fiscal_year_type.id)) date_ranges = self.env['date.range'].search(date_range_domain) + if not date_ranges: + return [('id', '=', False)] + domain = [] for date_range in date_ranges: domain = expression.OR([domain, [ diff --git a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py index 59fabd0bd..39bb3356d 100644 --- a/account_move_fiscal_year/tests/test_account_move_fiscal_year.py +++ b/account_move_fiscal_year/tests/test_account_move_fiscal_year.py @@ -131,3 +131,10 @@ class TestAccountMoveFiscalYear(TransactionCase): move_2018 in moves, move_2019 not in moves, ])) + # Search non existing year + moves = self.AccountMoveObj.search([ + ('date_range_fy_id', 'ilike', '2016'), + ]) + self.assertFalse( + moves + )