Skip to content
Snippets Groups Projects
Commit 121a1cd601e8 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Migrate to Odoo 13.0

Specifics to play better with accounting changes:

* No longer change the base ``date`` field; add ``accounting_date`` instead.
* Build periods when loading accounting data for a new company.
parent c1c265ef7513
No related branches found
No related tags found
No related merge requests found
Showing
with 231 additions and 316 deletions
include:
- project: xcg/ci-templates
file: /odoo/11.0/gitlab-ci.yaml
file: /odoo/13.0/gitlab-ci.yaml
13.0.1.0.0
----------
* Migrate to Odoo 13.0. In the process, to play better with accounting changes:
* No longer change the base ``date`` field; add ``accounting_date`` instead.
* Build periods when loading accounting data for a new company.
11.0.1.2
--------
......
# flake8: noqa
from . import models, wizards
from . import models, wizards # noqa: F401
......@@ -22,8 +22,8 @@
"name": "Accounting Periods",
"license": "AGPL-3",
"summary": "Add period accounting concept",
"version": "11.0.1.2",
"category": "Accounting",
"version": "13.0.1.0.0",
"category": "Accounting/Accounting",
"author": "XCG Consulting",
"website": "http://odoo.consulting/",
"depends": ["account"],
......@@ -35,6 +35,5 @@
"views/account_period.xml",
"views/account_fiscalyear.xml",
],
"demo": ["demo/account_fiscalyear_and_periods.xml"],
"installable": True,
}
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Load default fiscal years and periods when building a demo database. This
matters when running automated tests. -->
<!-- The defs below are similar to those in odoo8/addons/account/demo/account_demo.xml. -->
<record id="data_fiscalyear" model="account.fiscalyear">
<field name="name" eval="'Fiscal Year X '+time.strftime('%Y')" />
<field name="code" eval="'FY'+time.strftime('%Y')" />
<field name="company_id" ref="base.main_company" />
<field name="date_stop" eval="time.strftime('%Y')+'-12-31'" />
</record>
<record id="period_1" model="account.period">
<field name="code" eval="'01/'+time.strftime('%Y')" />
<field name="name" eval="'X 01/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-01-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-01-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_2" model="account.period">
<field name="code" eval="'02/'+time.strftime('%Y')" />
<field name="name" eval="'X 02/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-02-01'" />
<!-- Last day of February: 1 day before March 1st. -->
<field name="date_stop"
eval="(DateTime.today().replace(month=3, day=1) - timedelta(days=1)).strftime('%Y-%m-%d')" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_3" model="account.period">
<field name="code" eval="'03/'+time.strftime('%Y')" />
<field name="name" eval="'X 03/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-03-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-03-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_4" model="account.period">
<field name="code" eval="'04/'+time.strftime('%Y')" />
<field name="name" eval="'X 04/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-04-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-04-30'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_5" model="account.period">
<field name="code" eval="'05/'+time.strftime('%Y')" />
<field name="name" eval="'X 05/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-05-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-05-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_6" model="account.period">
<field name="code" eval="'06/'+time.strftime('%Y')" />
<field name="name" eval="'X 06/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-06-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-06-30'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_7" model="account.period">
<field name="code" eval="'07/'+time.strftime('%Y')" />
<field name="name" eval="'X 07/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-07-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-07-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_8" model="account.period">
<field name="code" eval="'08/'+time.strftime('%Y')" />
<field name="name" eval="'X 08/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-08-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-08-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_9" model="account.period">
<field name="code" eval="'09/'+time.strftime('%Y')" />
<field name="name" eval="'X 09/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-09-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-09-30'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_10" model="account.period">
<field name="code" eval="'10/'+time.strftime('%Y')" />
<field name="name" eval="'X 10/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-10-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-10-31'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_11" model="account.period">
<field name="code" eval="'11/'+time.strftime('%Y')" />
<field name="name" eval="'X 11/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-11-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-11-30'" />
<field name="company_id" ref="base.main_company" />
</record>
<record id="period_12" model="account.period">
<field name="code" eval="'12/'+time.strftime('%Y')" />
<field name="name" eval="'X 12/'+time.strftime('%Y')" />
<field name="fiscalyear_id" ref="data_fiscalyear" />
<field name="date_start" eval="time.strftime('%Y')+'-12-01'" />
<field name="date_stop" eval="time.strftime('%Y')+'-12-31'" />
<field name="company_id" ref="base.main_company" />
</record>
</odoo>
# flake8: noqa
from . import (
from . import ( # noqa: F401
account_chart_template,
account_fiscalyear,
account_move,
account_move_line,
......
##############################################################################
#
# Accounting Periods, for Odoo
# Copyright (C) 2020 XCG Consulting <http://odoo.consulting>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models
class AccountChartTemplate(models.Model):
"""Build periods when loading accounting data for a new company.
"""
_inherit = "account.chart.template"
def _load(self, sale_tax_rate, purchase_tax_rate, company):
""" Installs this chart of accounts on the current company, replacing
the existing one if it had already one defined. If some accounting
entries had already been made, this function fails instead, triggering
a UserError.
Also, note that this function can only be run by someone with
administration rights.
Override this method defined in the "account" module:
* Build periods when loading accounting data for a new company.
"""
ret = super(AccountChartTemplate, self)._load(
sale_tax_rate, purchase_tax_rate, company
)
end_date = fields.Date.today().replace(
day=company.fiscalyear_last_day,
month=int(company.fiscalyear_last_month or "12"),
)
year_str = str(end_date.year)
self.env["account.fiscalyear"].create(
{
"code": year_str,
"company_id": company.id,
"date_stop": end_date,
"name": year_str,
}
).create_period()
return ret
......@@ -46,7 +46,7 @@
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda rec: rec.env.user.company_id,
default=lambda rec: rec.env.company,
help="The company the fiscal year is in.",
required=True,
index=True,
......@@ -85,9 +85,8 @@
)
]
@api.multi
@api.depends("date_stop")
def _compute_date_start(self):
for fiscalyear in self:
if not fiscalyear.date_stop:
continue
......@@ -89,11 +88,10 @@
@api.depends("date_stop")
def _compute_date_start(self):
for fiscalyear in self:
if not fiscalyear.date_stop:
continue
fiscalyear.date_start = fields.Date.to_string(
fields.Date.from_string(fiscalyear.date_stop)
- fiscalyear._get_duration()
fiscalyear.date_start = (
fiscalyear.date_stop - fiscalyear._get_duration()
)
@api.constrains("date_stop")
......@@ -101,8 +99,8 @@
""" Check end date value when fiscal
year last day/month is provided.
"""
config_fy_month = self.env.user.company_id.fiscalyear_last_month
config_fy_day = self.env.user.company_id.fiscalyear_last_day
config_fy_month = self.env.company.fiscalyear_last_month # str
config_fy_day = self.env.company.fiscalyear_last_day # int
if not config_fy_day and not config_fy_month:
return
......@@ -106,8 +104,8 @@
if not config_fy_day and not config_fy_month:
return
ed = fields.Date.from_string(self.date_stop)
if ed.month != config_fy_month or ed.day != config_fy_day:
ed = self.date_stop
if str(ed.month) != config_fy_month or ed.day != config_fy_day:
raise ValidationError(
_(
"The end date must match the fiscal "
......@@ -116,7 +114,6 @@
% (config_fy_month, config_fy_day)
)
@api.multi
def create_period(self):
""" Call by the "Create Periods" Button.
......@@ -124,8 +121,8 @@
automatically all periods.
"""
for fy in self:
ed = fields.Date.from_string(fy.date_stop)
ed = fy.date_stop
sd = ed - fy._get_duration()
while sd < ed:
period_ed = sd + relativedelta(months=1, days=-1)
......@@ -128,9 +125,9 @@
sd = ed - fy._get_duration()
while sd < ed:
period_ed = sd + relativedelta(months=1, days=-1)
if fields.Date.to_string(period_ed) > fy.date_stop:
period_ed = fields.Date.from_string(fy.date_stop)
if period_ed > fy.date_stop:
period_ed = fy.date_stop
fy.write(
{
......@@ -160,7 +157,6 @@
# handle shorter or longer fiscal year
return relativedelta(months=12, days=-1)
@api.multi
def action_realloc_period_am(self):
""" Call by the "Reallocate Periods" action.
......@@ -213,5 +209,6 @@
: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 dt:
dt = fields.Date.context_today(self)
......@@ -216,9 +213,10 @@
if not dt:
dt = fields.Date.context_today(self)
args = [("date_start", "<=", dt), ("date_stop", ">=", dt)]
if self.env.context.get("company_id", False):
company_id = self.env.context["company_id"]
else:
company_id = self.env.user.company_id.id
args.append(("company_id", "=", company_id))
return self.search(args)
company_id = self.env.context.get("company_id") or self.env.company.id
return self.search(
[
("date_start", "<=", dt),
("date_stop", ">=", dt),
("company_id", "=", company_id),
]
)
......@@ -29,6 +29,13 @@
_inherit = "account.move"
accounting_date = fields.Date(
string="Accounting date",
copy=False,
help="Validation date of the accounting document.",
readonly=True,
)
period_id = fields.Many2one(
comodel_name="account.period",
string="Period",
......@@ -32,4 +39,5 @@
period_id = fields.Many2one(
comodel_name="account.period",
string="Period",
ondelete="restrict",
help="The period this accounting document is in.",
......@@ -35,7 +43,6 @@
help="The period this accounting document is in.",
ondelete="restrict",
states={"posted": [("readonly", True), ("required", True)]},
)
transaction_date = fields.Date(
string="Transaction date",
......@@ -37,10 +44,11 @@
states={"posted": [("readonly", True), ("required", True)]},
)
transaction_date = fields.Date(
string="Transaction date",
copy=False,
help=(
"Invoicing date when provided; otherwise this is the accounting "
"date."
),
states={"posted": [("readonly", True)]},
......@@ -42,8 +50,7 @@
help=(
"Invoicing date when provided; otherwise this is the accounting "
"date."
),
states={"posted": [("readonly", True)]},
copy=False,
)
......@@ -48,7 +55,7 @@
)
@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
"""Override to set a transaction date from invoices.
"""
......@@ -52,19 +59,8 @@
"""Override to set a transaction date from invoices.
"""
if not vals.get("date"):
vals["date"] = fields.Date.context_today(self)
invoice = self.env.context.get("invoice")
if invoice and isinstance(invoice, models.BaseModel):
if not isinstance(vals, dict):
vals = {}
vals["transaction_date"] = invoice.date_invoice
return super(AccountMove, self).create(vals)
@api.model
def fields_get(self, allfields=None, attributes=None):
"""Override to tweak the default "date" field.
"""
for vals in vals_list:
invoice_date = vals.get("invoice_date")
if invoice_date:
vals["transaction_date"] = invoice_date
......@@ -70,5 +66,3 @@
ret = super(AccountMove, self).fields_get(
allfields=allfields, attributes=attributes
)
return super(AccountMove, self).create(vals_list)
......@@ -74,16 +68,2 @@
date_field = ret.get("date")
if date_field:
date_field.update(
{
"string": _("Accounting date"),
"help": _("Validation date of the accounting document."),
"readonly": True,
"states": {},
}
)
return ret
@api.multi
def post(self):
......@@ -89,10 +69,9 @@
def post(self):
"""Override accounting document validation to:
- Set accounting dates (default "date" field).
- Also set the transaction date ("transaction_date" field) when empty.
"""Override accounting document validation to fill accounting dates &
period.
"""
self.fill_accounting_dates()
return super(AccountMove, self).post()
......@@ -93,8 +72,7 @@
"""
self.fill_accounting_dates()
return super(AccountMove, self).post()
@api.multi
def fill_accounting_dates(self):
......@@ -100,5 +78,5 @@
def fill_accounting_dates(self):
"""- Set accounting dates (default "date" field).
"""- Set the accounting date.
- Also set the transaction date ("transaction_date" field) when empty.
- Force the period to always be around the current date.
- Only select open periods.
......@@ -115,7 +93,7 @@
# context has provided.
if self.env.context.get("force_period_on_date"):
# If accounting document date is empty, get today date.
acc_date = fields.Date.from_string(accdoc.date) or acc_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(
......@@ -137,8 +115,8 @@
# last day of the period.
in_cutoff = False
if accdoc.journal_id.type == "sale":
period_end = fields.Date.from_string(period.date_stop)
period_end = period.date_stop
in_cutoff = acc_date > period_end
acc_date = period_end if in_cutoff else acc_date
# The data to update the accounting document with.
......@@ -141,8 +119,11 @@
in_cutoff = acc_date > period_end
acc_date = period_end if in_cutoff else acc_date
# The data to update the accounting document with.
accdoc_values = {"date": acc_date, "period_id": period.id}
accdoc_values = {
"accounting_date": acc_date,
"period_id": period.id,
}
# Set a transaction date when no previous one set. Also, force it
# during cut-off.
......
......@@ -59,7 +59,6 @@
)
@api.depends("date_cutoff", "date_stop")
@api.multi
def _get_date_effective_cutoff(self):
for period in self:
period.date_effective_cutoff = (
......@@ -110,6 +109,5 @@
)
]
@api.model
def find(self, dt=None):
......@@ -114,7 +112,5 @@
def find(self, dt=None):
context = dict(self.env.context)
if not dt:
dt = fields.Date.context_today(self)
......@@ -118,18 +114,14 @@
if not dt:
dt = fields.Date.context_today(self)
args = [("date_start", "<=", dt), ("date_stop", ">=", dt)]
if context.get("company_id", False):
args.append(("company_id", "=", context["company_id"]))
else:
company_id = self.env.user.company_id.id
args.append(("company_id", "=", company_id))
result = []
if not result:
result = self.search(args)
company_id = self.env.context.get("company_id") or self.env.company.id
result = self.search(
[
("date_start", "<=", dt),
("date_stop", ">=", dt),
("company_id", "=", company_id),
]
)
if not result:
......@@ -154,8 +146,8 @@
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""Override to add company filter."""
args.append(("company_id", "=", self.env.user.company_id.id))
args.append(("company_id", "=", self.env.company.id))
return super(AccountPeriod, self).name_search(
name=name, args=args, operator=operator, limit=limit
)
......@@ -158,8 +150,7 @@
return super(AccountPeriod, self).name_search(
name=name, args=args, operator=operator, limit=limit
)
@api.multi
def reopen_period(self):
"""Called by a button to re-open a closed period."""
......
......@@ -8,7 +8,7 @@
[
'|',
('company_id', '=', False),
('company_id', 'child_of', [user.company_id.id]),
('company_id', 'in', company_ids),
]
]]></field>
<field name="global" eval="True" />
......@@ -21,7 +21,7 @@
[
'|',
('company_id', '=', False),
('company_id', 'child_of', [user.company_id.id]),
('company_id', 'in', company_ids),
]
]]></field>
<field name="global" eval="True" />
......
# flake8: noqa
from . import test_account_fiscalyear, test_account_period
from . import test_account_fiscalyear, test_account_period # noqa: F401
......@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo.tests import TransactionCase
import odoo.fields
import odoo.tests
......@@ -21,8 +23,13 @@
class Test(TransactionCase):
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
class Test(odoo.tests.TransactionCase):
"""Fiscal year & period creation tests.
"""
def test_create_period(self):
fiscalyear = self.env["account.fiscalyear"].create(
{
"code": "something",
"name": "anything",
......@@ -24,9 +31,9 @@
def test_create_period(self):
fiscalyear = self.env["account.fiscalyear"].create(
{
"code": "something",
"name": "anything",
"date_stop": "2017-12-31",
"date_stop": odoo.fields.Date.to_date("2017-12-31"),
}
)
fiscalyear.create_period()
......@@ -45,7 +52,11 @@
{"fiscalyear_last_month": "9", "fiscalyear_last_day": 20}
)
fiscalyear = self.env["account.fiscalyear"].create(
{"code": "another", "name": "more", "date_stop": "1977-09-20"}
{
"code": "another",
"name": "more",
"date_stop": odoo.fields.Date.to_date("1977-09-20"),
}
)
fiscalyear.create_period()
self.assertEqual(len(fiscalyear.period_ids), 12)
......
......@@ -18,11 +18,5 @@
#
##############################################################################
import logging
import odoo
from .util.odoo_tests import TestBase
from .util.singleton import Singleton
from .util.uuidgen import genUuid
import uuid
......@@ -28,12 +22,7 @@
log = logging.getLogger(__name__)
class TestMemory(object, metaclass=Singleton):
"""Keep records in memory across tests."""
pass
import odoo.fields
import odoo.tests
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
......@@ -36,11 +25,11 @@
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
class Test(TestBase):
class Test(odoo.tests.TransactionCase):
"""Test fiscal years & accounting periods.
These tests assume an Odoo database with demo data.
"""
def setUp(self):
......@@ -41,13 +30,9 @@
"""Test fiscal years & accounting periods.
These tests assume an Odoo database with demo data.
"""
def setUp(self):
super(Test, self).setUp()
self.memory = TestMemory()
def test_0000_create_accounting_account(self):
"""Create accounting accounts for use in further tests.
"""Set up base elements we are going to use in these tests.
"""
......@@ -52,6 +37,4 @@
"""
acctype, = self.createAndTest(
"account.account.type", [{"name": genUuid(), "type": "other"}]
)
super(Test, self).setUp()
......@@ -57,14 +40,3 @@
self.memory.account, = self.createAndTest(
"account.account",
[
{
"code": genUuid(max_chars=4),
"internal_type": "other",
"name": genUuid(max_chars=8),
"reconcile": True,
"user_type_id": acctype.id,
}
],
)
self.client = self._createPartner()
......@@ -70,9 +42,4 @@
def test_0001_create_partners(self):
"""Create simple partners, that will be used in other tests.
"""
self.memory.partner, = self.createAndTest(
"res.partner", [{"customer": True, "name": genUuid()}]
)
self.product = self.env.ref("product.product_product_1")
self.product_account = self._createAccount("other")
......@@ -78,16 +45,5 @@
def test_0002_create_products(self):
"""Create products for use in further tests.
"""
self.memory.product = self.browse_ref("product.service_cost_01").copy()
self.memory.product.write(
{
"property_account_expense_id": self.memory.account.id,
"property_account_income_id": self.memory.account.id,
}
)
def test_0100_invoice_dates(self):
def test_invoice_dates(self):
"""Check invoice date propagation to accounting documents.
"""
......@@ -96,9 +52,9 @@
period_today = self._getTodayPeriod()
# Control: Default dates & period around today.
invoice = self._makeInvoice()
self._validateInvoice(invoice)
accdoc = invoice.move_id
accdoc = self._makeInvoice()
self._validateInvoice(accdoc)
self.assertEqual(accdoc.accounting_date, today)
self.assertEqual(accdoc.date, today)
self.assertEqual(accdoc.transaction_date, today)
self.assertEqual(accdoc.period_id.id, period_today.id)
......@@ -107,12 +63,12 @@
self.assertEqual(accentries.mapped("period_id").id, period_today.id)
# Force a date on the invoice; check its propagation.
invoice = self._makeInvoice()
invoice.date_invoice = "2017-01-15"
self._validateInvoice(invoice)
accdoc = invoice.move_id
self.assertEqual(accdoc.date, today)
self.assertEqual(accdoc.transaction_date, "2017-01-15")
forced_date = odoo.fields.Date.to_date("2017-01-15")
accdoc = self._makeInvoice(invoice_date=forced_date)
self._validateInvoice(accdoc)
self.assertEqual(accdoc.accounting_date, today)
self.assertEqual(accdoc.date, forced_date) # unchanged odoo field
self.assertEqual(accdoc.transaction_date, forced_date)
self.assertEqual(accdoc.period_id.id, period_today.id)
accentries = accdoc.line_ids
self.assertEqual(
......@@ -116,7 +72,7 @@
self.assertEqual(accdoc.period_id.id, period_today.id)
accentries = accdoc.line_ids
self.assertEqual(
set(accentries.mapped("transaction_date")), {"2017-01-15"}
set(accentries.mapped("transaction_date")), {forced_date}
)
self.assertEqual(accentries.mapped("period_id").id, period_today.id)
......@@ -120,7 +76,7 @@
)
self.assertEqual(accentries.mapped("period_id").id, period_today.id)
def test_0900_close_period(self):
def test_close_period(self):
"""Check the "Close period" dialog box.
"""
......@@ -141,6 +97,42 @@
with self.assertRaises(odoo.exceptions.Warning):
self._validateInvoice(invoice)
def _createAccount(self, account_type):
"""Create an account.
:type account_type: String.
:rtype: Odoo "account.account" record.
"""
return self.env["account.account"].create(
{
"code": uuid.uuid4().hex[:8],
"internal_type": account_type,
"name": uuid.uuid4().hex,
"reconcile": True,
"user_type_id": (
self.env["account.account.type"]
.search([("type", "=", account_type)], limit=1)
.id
),
}
)
def _createPartner(self):
"""Create a client.
:rtype: Odoo "res.partner" record.
"""
account = self._createAccount("receivable")
return self.env["res.partner"].create(
{
"is_company": True,
"name": "TEST-PARTNER-NAME",
"property_account_receivable_id": account.id,
}
)
def _getTodayPeriod(self):
"""Find the period around today. We should have one in demo data.
......@@ -159,6 +151,6 @@
self.assertEqual(len(period_today), 1)
return period_today
def _makeInvoice(self):
def _makeInvoice(self, **invoice_values):
"""Create an invoice and return it.
......@@ -163,3 +155,5 @@
"""Create an invoice and return it.
:param invoice_values: kwargs to customize invoice creation values.
:return: The invoice.
......@@ -165,4 +159,4 @@
:return: The invoice.
:rtype: Odoo "account.invoice" record set.
:rtype: Odoo "account.move" record.
"""
......@@ -167,20 +161,16 @@
"""
# Create the invoice first and add lines afterwards.
invoice, = self.createAndTest(
"account.invoice",
[{"partner_id": self.memory.partner.id, "type": "out_invoice"}],
)
self.createAndTest(
"account.invoice.line",
[
{
"account_id": self.memory.account.id,
"invoice_id": invoice.id,
"name": genUuid(),
"price_unit": 42.0,
"product_id": self.memory.product.id,
}
local_invoice_values = {
"invoice_line_ids": [
(
0, # 0: Create.
0,
{
"account_id": self.product_account.id,
"name": "TEST-INVLINE",
"price_unit": 42.0,
"product_id": self.product.id,
"quantity": 1.0,
},
)
],
......@@ -186,8 +176,10 @@
],
)
return invoice
"partner_id": self.client.id,
"type": "out_invoice",
}
local_invoice_values.update(invoice_values)
return self.env["account.move"].create(local_invoice_values)
def _validateInvoice(self, invoice):
"""Validate the specified invoice.
......@@ -190,8 +182,8 @@
def _validateInvoice(self, invoice):
"""Validate the specified invoice.
:type invoice: Odoo "account.invoice" record set.
:type invoice: Odoo "account.move" record.
"""
self.assertEqual(invoice.state, "draft")
......@@ -195,5 +187,5 @@
"""
self.assertEqual(invoice.state, "draft")
invoice.action_invoice_open()
self.assertEqual(invoice.state, "open")
invoice.post()
self.assertEqual(invoice.state, "posted")
......@@ -90,7 +90,6 @@
<field name="name">Fiscal years</field>
<field name="res_model">account.fiscalyear</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>
<menuitem id="account_fiscalyear_menu_command" parent="account.account_account_menu"
......
......@@ -15,6 +15,7 @@
<field name="period_id" options="{'no_create': 1}" states="posted" />
</xpath>
<xpath expr="//field[@name='date']" position="after">
<field name="accounting_date" />
<field name="transaction_date" />
</xpath>
......
......@@ -79,7 +79,6 @@
<field name="name">Periods</field>
<field name="res_model">account.period</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
</record>
<record id="redirect_warning_account_period_action" model="ir.actions.act_window">
......@@ -88,7 +87,6 @@
]]></field>
<field name="name">Periods</field>
<field name="res_model">account.period</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
......
# flake8: noqa
from . import account_period_close
from . import account_period_close # noqa: F401
......@@ -19,7 +19,7 @@
#
##############################################################################
from odoo import api, fields, models
from odoo import fields, models
class AccountPeriodClose(models.TransientModel):
......@@ -34,7 +34,6 @@
help="Checking this box will confirm period closure.",
)
@api.multi
def close(self):
"""Method to close periods.
"""
......
......@@ -25,7 +25,6 @@
<field name="binding_model_id" ref="account_period.model_account_period" />
<field name="name">Close a period</field>
<field name="res_model">account.period.close</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_account_period_close"/>
<field name="target">new</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