Skip to content
Snippets Groups Projects

Add period_id in aml tree view (cf account_consult MO16-190)

Merged arthur.mayer requested to merge topic/16.0/MO16-190 into branch/16.0
4 files
+ 35
67
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 34
38
@@ -17,7 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
from odoo import _, exceptions, fields, models, tools
@@ -21,8 +20,6 @@
from odoo import _, exceptions, fields, models, tools
_logger = logging.getLogger(__name__)
class AccountMove(models.Model):
"""Add a period & dates onto accounting documents."""
@@ -40,7 +37,6 @@
def action_post(self):
"""Override accounting document validation to fill period."""
self.fetch_period()
test = super().action_post()
return test
self.fill_period()
return super().action_post()
@@ -46,9 +42,6 @@
def fetch_period(self):
"""Force the period to always be around the current date.
Only select open periods.
"""
def fill_period(self):
"""Find an open period around move date, set it onto that move."""
today = fields.Date.today()
for accdoc in self:
@@ -52,6 +45,5 @@
today = fields.Date.today()
for accdoc in self:
# Cache some data.
acc_date = accdoc.date or today
company = accdoc.company_id
@@ -56,5 +48,10 @@
acc_date = accdoc.date or today
company = accdoc.company_id
period_domain = [
("company_id", "=", company.id),
("date_start", "<=", acc_date),
("date_effective_cutoff", ">=", acc_date),
]
# Periods are ordered by date so selecting the first one is fine.
period = self.env["account.period"].search(
@@ -58,12 +55,7 @@
# Periods are ordered by date so selecting the first one is fine.
period = self.env["account.period"].search(
[
("company_id", "=", company.id),
("date_start", "<=", acc_date),
("date_effective_cutoff", ">=", acc_date),
("state", "!=", "done"),
],
period_domain + [("state", "!=", "done")],
limit=1,
)
if not period:
@@ -67,9 +59,8 @@
limit=1,
)
if not period:
# if doing tests or installing demo data, and any matching period not
# closed
# Create missing periods on-the-fly when running tests / DB populate.
if (
tools.config["test_enable"]
or tools.config["test_file"]
or self.env.context.get("install_demo", False)
@@ -72,7 +63,8 @@
if (
tools.config["test_enable"]
or tools.config["test_file"]
or self.env.context.get("install_demo", False)
or hasattr(self.env.registry, "populated_models")
) and (
not self.env.context.get("period_close_enable")
or not self.env["account.period"].search(
@@ -76,12 +68,7 @@
) and (
not self.env.context.get("period_close_enable")
or not self.env["account.period"].search(
[
("company_id", "=", company.id),
("date_start", "<=", acc_date),
("date_effective_cutoff", ">=", acc_date),
("state", "=", "done"),
],
period_domain + [("state", "=", "done")],
limit=1,
)
):
@@ -85,14 +72,20 @@
limit=1,
)
):
start_date = acc_date.replace(month=1)
end_date = acc_date.replace(month=12)
year_str = str(end_date.year)
fiscalyear = self.env["account.fiscal.year"].search(
[("name", "=", year_str)], limit=1
) # Fiscal year already exists in this company; ?
year_start = acc_date.replace(day=1, month=1)
year_end = acc_date.replace(day=31, month=12)
fiscalyear = (
self.env["account.fiscal.year"]
.sudo()
.search(
[
("company_id", "=", company.id),
("date_from", "<=", year_start),
("date_to", ">=", year_end),
],
limit=1,
)
)
if not fiscalyear:
fiscalyear = (
self.env["account.fiscal.year"]
@@ -100,10 +93,10 @@
.create(
{
"company_id": company.id,
"date_from": start_date,
"date_to": end_date,
"name": str(end_date.year),
"date_from": year_start,
"date_to": year_end,
"name": str(acc_date.year),
}
)
)
fiscalyear.create_periods()
@@ -106,8 +99,11 @@
}
)
)
fiscalyear.create_periods()
period = fiscalyear.period_ids[0]
period = self.env["account.period"].search(
period_domain + [("state", "!=", "done")],
limit=1,
)
else:
raise exceptions.UserError(
Loading