Skip to content
Snippets Groups Projects
Commit 26583cc1a1db authored by Etienne Ferriere's avatar Etienne Ferriere
Browse files

It must be possible to modify the period or the accounting date on an invoice

or an accounting document.
Updated the translations.
parent 4d99f59c664a
No related branches found
No related tags found
No related merge requests found
Pipeline #11301 passed
......@@ -6,8 +6,8 @@
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-23 15:46+0000\n"
"PO-Revision-Date: 2020-04-23 17:47+0200\n"
"POT-Creation-Date: 2021-02-18 09:44+0000\n"
"PO-Revision-Date: 2021-02-18 10:45+0100\n"
"Last-Translator: Houzéfa Abbasbhay <houzefa.abba@xcg-consulting.fr>\n"
"Language-Team: XCG Consulting\n"
"Language: fr\n"
......@@ -15,7 +15,7 @@
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 2.0.6\n"
"X-Generator: Poedit 2.3\n"
#. module: account_period
#: model:ir.model,name:account_period.model_account_chart_template
......@@ -307,6 +307,24 @@
msgstr "Date de fin"
#. module: account_period
#: code:addons/account_period/models/account_move.py:0
#, python-format
msgid ""
"The accounting date must be anterior to the validation date or the same."
msgstr ""
"La date de comptabilisation doit correspondre à la date de validation ou lui "
"être antérieure."
#. module: account_period
#: code:addons/account_period/models/account_move.py:0
#, python-format
msgid ""
"The accounting period must match the validation date or be anterior to it."
msgstr ""
"La période comptable doit correspondre à la date de validation ou lui être "
"antérieure."
#. module: account_period
#: model:ir.model.constraint,message:account_period.constraint_account_fiscalyear_unique_code_per_company
#: model:ir.model.constraint,message:account_period.constraint_account_period_unique_code_per_company
msgid "The code must be unique."
......
......@@ -33,7 +33,9 @@
string="Accounting date",
copy=False,
help="Validation date of the accounting document.",
readonly=True,
states={"posted": [("readonly", True), ("required", True)]},
required=False,
readonly=False,
)
period_id = fields.Many2one(
......@@ -42,6 +44,8 @@
ondelete="restrict",
help="The period this accounting document is in.",
states={"posted": [("readonly", True), ("required", True)]},
required=False,
readonly=False,
)
transaction_date = fields.Date(
......@@ -71,7 +75,8 @@
period.
"""
self.check_accounting_date_integrity()
self.fill_accounting_dates()
return super(AccountMove, self).post()
......@@ -74,7 +79,43 @@
self.fill_accounting_dates()
return super(AccountMove, self).post()
def check_accounting_date_integrity(self):
if any(
self.mapped(
lambda r: (
r.accounting_date > fields.Date.today()
if r.accounting_date
else False
)
)
):
raise exceptions.ValidationError(
_(
"The accounting date must be anterior to the validation "
"date or the same."
)
)
return True
def check_period_integrity(self):
if any(
self.mapped(lambda r: r.period_id.date_start > fields.Date.today())
):
raise exceptions.ValidationError(
_(
"The accounting period must match the validation "
"date or be anterior to it."
)
)
return True
def fill_accounting_dates(self):
"""- Set the accounting date.
- Also set the transaction date ("transaction_date" field) when empty.
......@@ -82,7 +123,7 @@
- Only select open periods.
"""
acc_date = datetime.date.today()
today = datetime.date.today()
for accdoc in self:
......@@ -86,6 +127,8 @@
for accdoc in self:
acc_date = accdoc.accounting_date or today
# Cache some data.
company = accdoc.company_id
......@@ -95,18 +138,15 @@
# If accounting document date is empty, get today date.
acc_date = accdoc.date or acc_date
# 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"),
],
limit=1,
)
if not period:
raise exceptions.Warning(
_('No period found around %s in the "%s" company.')
% (acc_date, company.sudo().name)
if not accdoc.period_id:
# 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"),
],
limit=1,
)
......@@ -112,4 +152,15 @@
)
if not period:
raise exceptions.Warning(
_('No period found around %s in the "%s" company.')
% (acc_date, company.sudo().name)
)
accdoc_values = {"period_id": period.id}
else:
accdoc.check_period_integrity()
period = accdoc.period_id
accdoc_values = {}
# When we are between the period end and cut-off date, force the
# last day of the period.
......@@ -120,10 +171,7 @@
acc_date = period_end if in_cutoff else acc_date
# The data to update the accounting document with.
accdoc_values = {
"accounting_date": acc_date,
"period_id": period.id,
}
accdoc_values.update({"accounting_date": acc_date})
# Set a transaction date when no previous one set. Also, force it
# during cut-off.
......
......@@ -12,7 +12,7 @@
<!-- Add fields. -->
<xpath expr="//field[@name='date']" position="before">
<field name="period_id" options="{'no_create': 1}" states="posted" />
<field name="period_id" options="{'no_create': 1}" />
</xpath>
<xpath expr="//field[@name='date']" position="after">
<field name="accounting_date" />
......@@ -16,7 +16,8 @@
</xpath>
<xpath expr="//field[@name='date']" position="after">
<field name="accounting_date" />
<field name="transaction_date" />
<field name="transaction_date"
attrs="{'invisible': [('type', '!=', 'entry')]}" />
</xpath>
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment