Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
5
account_move_fiscal_year/models/__init__.py
Executable file
5
account_move_fiscal_year/models/__init__.py
Executable file
@@ -0,0 +1,5 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import account_move
|
||||
from . import account_move_line
|
||||
from . import res_company
|
||||
49
account_move_fiscal_year/models/account_move.py
Executable file
49
account_move_fiscal_year/models/account_move.py
Executable file
@@ -0,0 +1,49 @@
|
||||
# Copyright 2017 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
date_range_fy_id = fields.Many2one(
|
||||
comodel_name="account.fiscal.year",
|
||||
string="Fiscal year",
|
||||
compute="_compute_date_range_fy",
|
||||
search="_search_date_range_fy",
|
||||
)
|
||||
|
||||
@api.depends("date", "company_id")
|
||||
def _compute_date_range_fy(self):
|
||||
for rec in self:
|
||||
date = fields.Date.to_date(rec.date)
|
||||
company = rec.company_id
|
||||
rec.date_range_fy_id = company and company.find_daterange_fy(date) or False
|
||||
|
||||
@api.model
|
||||
def _search_date_range_fy(self, operator, value):
|
||||
if operator in ("=", "!=", "in", "not in"):
|
||||
date_range_domain = [("id", operator, value)]
|
||||
else:
|
||||
date_range_domain = [("name", operator, value)]
|
||||
|
||||
date_ranges = self.env["account.fiscal.year"].search(date_range_domain)
|
||||
|
||||
domain = [("id", "=", -1)]
|
||||
for date_range in date_ranges:
|
||||
domain = expression.OR(
|
||||
[
|
||||
domain,
|
||||
[
|
||||
"&",
|
||||
("date", ">=", date_range.date_from),
|
||||
("date", "<=", date_range.date_to),
|
||||
"|",
|
||||
("company_id", "=", False),
|
||||
("company_id", "=", date_range.company_id.id),
|
||||
],
|
||||
]
|
||||
)
|
||||
return domain
|
||||
12
account_move_fiscal_year/models/account_move_line.py
Executable file
12
account_move_fiscal_year/models/account_move_line.py
Executable file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2017 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
date_range_fy_id = fields.Many2one(
|
||||
related="move_id.date_range_fy_id",
|
||||
)
|
||||
24
account_move_fiscal_year/models/res_company.py
Executable file
24
account_move_fiscal_year/models/res_company.py
Executable file
@@ -0,0 +1,24 @@
|
||||
# Author: Damien Crier
|
||||
# Copyright 2016 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
def find_daterange_fy(self, date):
|
||||
"""
|
||||
try to find a date range with type 'fiscalyear'
|
||||
with @param:date contained in its date_start/date_end interval
|
||||
"""
|
||||
fiscalyear = self.env["account.fiscal.year"].search(
|
||||
[
|
||||
("company_id", "=", self.id),
|
||||
("date_from", "<=", date),
|
||||
("date_to", ">=", date),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
|
||||
return fiscalyear
|
||||
Reference in New Issue
Block a user