Skip to content

Commit

Permalink
[MIG] account_cutoff_base: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed Dec 6, 2024
1 parent 0ee62e6 commit 6e6d943
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 77 deletions.
10 changes: 5 additions & 5 deletions account_cutoff_base/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Account Cut-off Base
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--closing-lightgray.png?logo=github
:target: https://github.com/OCA/account-closing/tree/17.0/account_cutoff_base
:target: https://github.com/OCA/account-closing/tree/18.0/account_cutoff_base
:alt: OCA/account-closing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-closing-17-0/account-closing-17-0-account_cutoff_base
:target: https://translation.odoo-community.org/projects/account-closing-18-0/account-closing-18-0-account_cutoff_base
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-closing&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-closing&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -68,7 +68,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-closing/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-closing/issues/new?body=module:%20account_cutoff_base%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-closing/issues/new?body=module:%20account_cutoff_base%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -129,6 +129,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/account-closing <https://github.com/OCA/account-closing/tree/17.0/account_cutoff_base>`_ project on GitHub.
This module is part of the `OCA/account-closing <https://github.com/OCA/account-closing/tree/18.0/account_cutoff_base>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_cutoff_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Account Cut-off Base",
"version": "17.0.1.1.0",
"version": "18.0.1.0.0",
"category": "Accounting & Finance",
"summary": "Base module for Account Cut-offs",
"author": "Akretion,Odoo Community Association (OCA)",
Expand Down
64 changes: 39 additions & 25 deletions account_cutoff_base/models/account_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from dateutil.relativedelta import relativedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools import date_utils, float_is_zero
from odoo.tools.misc import format_date

Expand All @@ -35,10 +35,10 @@ def _compute_total_cutoff(self):
@property
def cutoff_type_label_map(self):
return {
"accrued_expense": _("Accrued Expense"),
"accrued_revenue": _("Accrued Revenue"),
"prepaid_revenue": _("Prepaid Revenue"),
"prepaid_expense": _("Prepaid Expense"),
"accrued_expense": self.env._("Accrued Expense"),
"accrued_revenue": self.env._("Accrued Revenue"),
"prepaid_revenue": self.env._("Prepaid Revenue"),
"prepaid_expense": self.env._("Prepaid Expense"),
}

@api.model
Expand Down Expand Up @@ -118,7 +118,7 @@ def _default_cutoff_account_id(self):
cutoff_account_id = fields.Many2one(
comodel_name="account.account",
string="Cut-off Account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
domain="[('deprecated', '=', False)]",
default=lambda self: self._default_cutoff_account_id(),
check_company=True,
tracking=True,
Expand Down Expand Up @@ -162,13 +162,25 @@ def _default_cutoff_account_id(self):
"the state is set to 'Done' and the fields become read-only.",
)

_sql_constraints = [
(
"date_type_company_uniq",
"unique(cutoff_date, company_id, cutoff_type)",
_("A cutoff of the same type already exists with this cut-off date !"),
)
]
@api.constrains("cutoff_date", "company_ids", "cutoff_type")
def _check_unique_cutoff(self):
for record in self:
existing = self.search(
[
("id", "!=", record.id),
("cutoff_date", "=", record.cutoff_date),
("company_ids", "in", record.company_id),
("cutoff_type", "=", record.cutoff_type),
],
limit=1,
)
if existing:
raise ValidationError(
record.env._(
"A cutoff of the same type already exists "
"with this cut-off date!"
)
)

def _compute_display_name(self):
type2label = self.cutoff_type_label_map
Expand Down Expand Up @@ -292,14 +304,14 @@ def create_move(self):
move_obj = self.env["account.move"]
if self.move_id:
raise UserError(
_(
self.env._(
"The Cut-off Journal Entry already exists. You should "
"delete it before running this function."
)
)
if not self.line_ids:
raise UserError(
_(
self.env._(
"There are no lines on this Cut-off, so we can't create "
"a Journal Entry."
)
Expand All @@ -315,12 +327,12 @@ def create_move(self):
if self.company_id.post_cutoff_move:
move._post(soft=False)
self.write({"move_id": move.id, "state": "done"})
self.message_post(body=_("Journal entry generated"))
self.message_post(body=self.env._("Journal entry generated"))

action = self.env.ref("account.action_move_journal_line").sudo().read()[0]
action.update(
{
"view_mode": "form,tree",
"view_mode": "form,list",
"res_id": move.id,
"view_id": False,
"views": False,
Expand All @@ -336,20 +348,22 @@ def get_lines(self):
# (e.g. account_cutoff_start_end_dates) add additional states
# and don't require self.cutoff_date
if self.state == "draft" and not self.cutoff_date:
raise UserError(_("Cutoff date is not set."))
raise UserError(self.env._("Cutoff date is not set."))
# Delete existing lines
self.line_ids.unlink()
self.message_post(body=_("Cut-off lines re-generated"))
self.message_post(body=self.env._("Cut-off lines re-generated"))

def unlink(self):
for rec in self:
if rec.state == "done":
raise UserError(
_("You cannot delete cutoff records that are in done state.")
self.env._(
"You cannot delete cutoff records that are in done state."
)
)
return super().unlink()

def button_line_tree(self):
def button_line_list(self):
action = self.env["ir.actions.actions"]._for_xml_id(
"account_cutoff_base.account_cutoff_line_action"
)
Expand Down Expand Up @@ -394,17 +408,17 @@ def _prepare_tax_lines(self, tax_compute_all_res, currency):
tax.account_accrued_expense_id
or self.company_id.default_accrued_expense_tax_account_id
)
tax_account_field_label = _("Accrued Expense Tax Account")
tax_account_field_label = self.env._("Accrued Expense Tax Account")
elif self.cutoff_type == "accrued_revenue":
tax_accrual_account = (
tax.account_accrued_revenue_id
or self.company_id.default_accrued_revenue_tax_account_id
)
tax_account_field_label = _("Accrued Revenue Tax Account")
tax_account_field_label = self.env._("Accrued Revenue Tax Account")

if not tax_accrual_account:
raise UserError(
_(
self.env._(
"Missing '%(tax_account_field_label)s'. You must configure it "
"on the tax '%(tax_display_name)s' or on the accounting "
"configuration page of the company '%(company)s'.",
Expand Down
4 changes: 2 additions & 2 deletions account_cutoff_base/models/account_cutoff_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class AccountCutoffMapping(models.Model):
account_id = fields.Many2one(
"account.account",
string="Regular Account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
domain="[('deprecated', '=', False)]",
required=True,
check_company=True,
)
cutoff_account_id = fields.Many2one(
"account.account",
string="Cut-off Account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
domain="[('deprecated', '=', False)]",
required=True,
check_company=True,
)
Expand Down
4 changes: 2 additions & 2 deletions account_cutoff_base/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class AccountTax(models.Model):
account_accrued_revenue_id = fields.Many2one(
comodel_name="account.account",
string="Accrued Revenue Tax Account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
domain="[('deprecated', '=', False)]",
check_company=True,
)
account_accrued_expense_id = fields.Many2one(
comodel_name="account.account",
string="Accrued Expense Tax Account",
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
domain="[('deprecated', '=', False)]",
check_company=True,
)
17 changes: 10 additions & 7 deletions account_cutoff_base/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Account Cut-off Base</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c91fa0d8a0b963e99f75960f254698491d21ad27e7073b99dd7676e8c158e912
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-closing/tree/17.0/account_cutoff_base"><img alt="OCA/account-closing" src="https://img.shields.io/badge/github-OCA%2Faccount--closing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-closing-17-0/account-closing-17-0-account_cutoff_base"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-closing&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-closing/tree/18.0/account_cutoff_base"><img alt="OCA/account-closing" src="https://img.shields.io/badge/github-OCA%2Faccount--closing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-closing-18-0/account-closing-18-0-account_cutoff_base"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-closing&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module contains the technical basis for other cut-off modules ; it
doesn’t provide useful features by itself. You need to install other
cut-off modules to get the useful features:</p>
Expand Down Expand Up @@ -416,7 +417,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-closing/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-closing/issues/new?body=module:%20account_cutoff_base%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-closing/issues/new?body=module:%20account_cutoff_base%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -452,13 +453,15 @@ <h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-closing/tree/17.0/account_cutoff_base">OCA/account-closing</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-closing/tree/18.0/account_cutoff_base">OCA/account-closing</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion account_cutoff_base/tests/test_account_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_default_cutoff_account_id(self):

company = self.env.company
random_account = self.env["account.account"].search(
[("company_id", "=", company.id)], limit=1
[("company_ids", "in", company.id)], limit=1
)
if random_account:
company.default_accrued_expense_account_id = random_account.id
Expand Down
Loading

0 comments on commit 6e6d943

Please sign in to comment.