mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] add a method on date_range object to retrieve FY start date from a date
This commit is contained in:
@@ -3,5 +3,6 @@
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import date_range
|
||||
from . import date_range_type
|
||||
from . import res_company
|
||||
|
||||
25
account_fiscal_year/models/date_range.py
Normal file
25
account_fiscal_year/models/date_range.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: Damien Crier
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from openerp import models
|
||||
from openerp.tools import (DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
|
||||
|
||||
class DateRange(models.Model):
|
||||
_inherit = 'date.range'
|
||||
|
||||
def find_daterange_fy_start(self, date):
|
||||
"""
|
||||
try to find a date range with type 'fiscalyear'
|
||||
with @param:date <= date_start
|
||||
"""
|
||||
fy_id = self.env.ref('account_fiscal_year.fiscalyear')
|
||||
date_str = date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
s_args = [
|
||||
('type_id', '=', fy_id.id),
|
||||
('date_start', '<=', date_str),
|
||||
('company_id', '=', self.company_id.id),
|
||||
]
|
||||
date_range = self.env['date.range'].search(s_args)
|
||||
return date_range.date_start
|
||||
Reference in New Issue
Block a user