Skip to content
Snippets Groups Projects

Create branch 16.0

Merged arthur.mayer requested to merge topic/16.0/migration-16.0 into branch/16.0
Compare and Show latest version
1 file
+ 1
43
Compare changes
  • Side-by-side
  • Inline
+ 1
43
@@ -86,46 +86,4 @@
self.ensure_one()
self.state = "draft"
def find(
self, date: Optional[datetime.date] = None, create: bool = False
) -> models.Model:
"""Return the fiscal years for the provided date.
:param date: date, if None, use today
:param create: indicate to create the fiscal year if set to True
:return: fiscal years that include the indicated date, using either the
company_id in the context or if not set, the user company_id
"""
if not date:
date = fields.Date.context_today(self)
company = (
self.env["res.company"].browse(self.env.context.get("company_id"))
if "company_id" in self.env.context
else self.env.company
)
result = self.search(
[
("date_start", "<=", date),
("date_end", ">=", date),
("company_id", "=", company.id),
]
)
if not result and create:
# assume fiscal year duration is one year
month = int(company.fiscalyear_last_month)
day = company.fiscalyear_last_day
if date < datetime.date(date.year, month, day):
year = date.year
else:
year = date.year + 1
result = self.create(
{
"name": str(year),
"date_start": datetime.date(year, month, day),
"company_id": company.id,
}
)
result.create_period()
return result
self.state = "draft"
\ No newline at end of file
Loading