Browse Source

[IMP] add account_fiscal_year dependency

pull/134/head
houssine 4 years ago
parent
commit
b333e333d5
  1. 1
      easy_my_coop_loan_account/__manifest__.py
  2. 1
      easy_my_coop_loan_account/models/__init__.py
  3. 46
      easy_my_coop_loan_account/models/account_fiscal_year.py

1
easy_my_coop_loan_account/__manifest__.py

@ -7,6 +7,7 @@
"version": "12.0.1.0.0",
"depends": [
"account",
"account_fiscal_year",
"easy_my_coop_loan",
],
"author": "Coop IT Easy SCRLfs",

1
easy_my_coop_loan_account/models/__init__.py

@ -1,3 +1,4 @@
from . import company
from . import loan_issue_line
from . import account_move
from . import account_fiscal_year

46
easy_my_coop_loan_account/models/account_fiscal_year.py

@ -0,0 +1,46 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Houssine BAKKALI <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
from odoo.exceptions import UserError
class AccountFiscalYear(models.Model):
_inherit = "account.fiscal.year"
@api.model
def get_ongoing_fiscal_year(self, company_id=None):
today = fields.Date.today()
fy = self.env["account.fiscal.year"].search([
('date_from', '>=', today),
('date_to', '<=', today),
('company_id', '=', company_id)
])
if not fy:
raise UserError("No fiscal year has been found for %d",
today)
if company_id:
return fy.filtered(lambda r: r.company_id == company_id)
return fy
@api.model
def get_next_fiscal_year(self, company_id=None):
nextyear = fields.Date.today() + relativedelta(years=+1)
fy = self.env["account.fiscal.year"].search([
('date_from', '>=', nextyear),
('date_to', '<=', nextyear),
('company_id', '=', company_id)
])
if not fy:
raise UserError("No next fiscal year has been found for %d",
nextyear)
if company_id:
return fy.filtered(lambda r: r.company_id == company_id)
return fy
Loading…
Cancel
Save