From 71512e6a1029a1c2c6b056a120a342da98715c53 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Thu, 12 Oct 2017 13:53:31 +0200 Subject: [PATCH 1/2] [FIX] Search method should only search on fiscal month date range --- account_move_fiscal_month/models/account_move.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/account_move_fiscal_month/models/account_move.py b/account_move_fiscal_month/models/account_move.py index fd1f9801b..2dbb6ca76 100644 --- a/account_move_fiscal_month/models/account_move.py +++ b/account_move_fiscal_month/models/account_move.py @@ -12,8 +12,15 @@ class AccountMove(models.Model): date_range_fm_id = fields.Many2one( comodel_name='date.range', string="Fiscal month", + domain=lambda self: self._get_date_range_fm_domain(), compute='_compute_date_range_fm', search='_search_date_range_fm') + @api.model + def _get_date_range_fm_domain(self): + fiscal_month_type = self.env.ref( + 'account_fiscal_month.date_range_fiscal_month') + return "[('type_id', '=', %d)]" % fiscal_month_type.id + @api.multi @api.depends('date', 'company_id') def _compute_date_range_fm(self): @@ -29,9 +36,14 @@ class AccountMove(models.Model): else: date_range_domain = [('name', operator, value)] + fiscal_month_type = self.env.ref( + 'account_fiscal_month.date_range_fiscal_month') + date_range_domain.append(('type_id', '=', fiscal_month_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, [ From 93b4ce40aef045628b59904f1c8d5d15fa146585 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Wed, 18 Oct 2017 09:28:54 +0200 Subject: [PATCH 2/2] [FIX] account_move_fiscal_month: check if the company is defined. --- account_move_fiscal_month/models/account_move.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/account_move_fiscal_month/models/account_move.py b/account_move_fiscal_month/models/account_move.py index 2dbb6ca76..39fa46b24 100644 --- a/account_move_fiscal_month/models/account_move.py +++ b/account_move_fiscal_month/models/account_move.py @@ -27,7 +27,8 @@ class AccountMove(models.Model): for rec in self: date = rec.date company = rec.company_id - rec.date_range_fm_id = company.find_daterange_fm(date) + rec.date_range_fm_id =\ + company and company.find_daterange_fm(date) or False @api.model def _search_date_range_fm(self, operator, value):