Skip to content

Commit

Permalink
[MIG] l10n_th_multicurrency_revaluation: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 authored and saran committed Nov 13, 2024
1 parent 49c4a31 commit c42b372
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 82 deletions.
12 changes: 6 additions & 6 deletions l10n_th_multicurrency_revaluation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thai Localization - Multicurrency Revaluation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bc6f54addb32f0123e0587cadbbe83876b356e3f0e7463fefd623b0c171af945
!! source digest: sha256:bfff2b0ecdece89174d89c9407fd523021a5f79030c0487ee3dadbc070ce6557
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand All @@ -17,13 +17,13 @@ Thai Localization - Multicurrency Revaluation
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--thailand-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-thailand/tree/15.0/l10n_th_multicurrency_revaluation
:target: https://github.com/OCA/l10n-thailand/tree/16.0/l10n_th_multicurrency_revaluation
:alt: OCA/l10n-thailand
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-thailand-15-0/l10n-thailand-15-0-l10n_th_multicurrency_revaluation
:target: https://translation.odoo-community.org/projects/l10n-thailand-16-0/l10n-thailand-16-0-l10n_th_multicurrency_revaluation
: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/l10n-thailand&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-thailand&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -85,7 +85,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-thailand/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/l10n-thailand/issues/new?body=module:%20l10n_th_multicurrency_revaluation%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-thailand/issues/new?body=module:%20l10n_th_multicurrency_revaluation%0Aversion:%2016.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 @@ -131,6 +131,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ps-tubtim|

This module is part of the `OCA/l10n-thailand <https://github.com/OCA/l10n-thailand/tree/15.0/l10n_th_multicurrency_revaluation>`_ project on GitHub.
This module is part of the `OCA/l10n-thailand <https://github.com/OCA/l10n-thailand/tree/16.0/l10n_th_multicurrency_revaluation>`_ 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 l10n_th_multicurrency_revaluation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Thai Localization - Multicurrency Revaluation",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-thailand",
"license": "AGPL-3",
Expand Down
50 changes: 30 additions & 20 deletions l10n_th_multicurrency_revaluation/models/account_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class AccountAccount(models.Model):

currency_revaluation = fields.Boolean(
string="Allow Currency Revaluation",
compute="_compute_currency_revaluation",
store=True,
readonly=False,
)

_sql_mapping = {
Expand All @@ -25,9 +28,9 @@ def init(self):
res = super().init()
accounts = self.env["account.account"].search(
[
("user_type_id.id", "in", self._get_revaluation_account_types()),
("account_type", "in", self._get_revaluation_account_types()),
("currency_revaluation", "=", False),
("user_type_id.include_initial_balance", "=", True),
("include_initial_balance", "=", True),
]
)
accounts.write({"currency_revaluation": True})
Expand All @@ -37,9 +40,7 @@ def write(self, vals):
if (
"currency_revaluation" in vals
and vals.get("currency_revaluation", False)
and any(
[not x for x in self.mapped("user_type_id.include_initial_balance")]
)
and any([not x for x in self.mapped("include_initial_balance")])
):
raise UserError(
_(
Expand All @@ -48,31 +49,40 @@ def write(self, vals):
"on these accounts: \n\t - %s"
)
% "\n\t - ".join(
self.filtered(
lambda x: not x.user_type_id.include_initial_balance
).mapped("name")
self.filtered(lambda x: not x.include_initial_balance).mapped(
"name"
)
)
)
return super(AccountAccount, self).write(vals)

def _get_revaluation_account_types(self):
return [
self.env.ref("account.data_account_type_receivable").id,
self.env.ref("account.data_account_type_payable").id,
self.env.ref("account.data_account_type_liquidity").id,
"asset_receivable",
"liability_payable",
"asset_cash",
"liability_credit_card",
]

@api.onchange("user_type_id")
def _onchange_user_type_id(self):
@api.depends("account_type")
def _compute_currency_revaluation(self):
revaluation_accounts = self._get_revaluation_account_types()
for rec in self:
if rec.user_type_id.id in revaluation_accounts:
if rec.account_type in revaluation_accounts:
rec.currency_revaluation = True
else:
rec.currency_revaluation = False

def _revaluation_query(self, revaluation_date, start_date=None):
tables, where_clause, where_clause_params = self.env[
"account.move.line"
]._query_get()
query = self.env["account.move.line"]._where_calc(
[
("company_id", "in", self.env.companies.ids),
("display_type", "not in", ("line_section", "line_note")),
("parent_state", "!=", "cancel"),
]
)
self.env["account.move.line"]._apply_ir_rules(query)
tables, where_clause, where_clause_params = query.get_sql()
mapping = [
('"account_move_line".', "aml."),
('"account_move_line"', "account_move_line aml"),
Expand All @@ -90,7 +100,7 @@ def _revaluation_query(self, revaluation_date, start_date=None):
aml.id,
aml.move_name,
aml.account_id,
CASE WHEN aat.type IN ('payable', 'receivable')
CASE WHEN acc.account_type IN ('asset_receivable', 'liability_payable')
THEN aml.partner_id
ELSE NULL
END AS partner_id,
Expand All @@ -103,7 +113,6 @@ def _revaluation_query(self, revaluation_date, start_date=None):
+ """
LEFT JOIN account_move am ON aml.move_id = am.id
INNER JOIN account_account acc ON aml.account_id = acc.id
INNER JOIN account_account_type aat ON acc.user_type_id = aat.id
LEFT JOIN account_partial_reconcile aprc
ON (aml.balance < 0 AND aml.id = aprc.credit_move_id)
LEFT JOIN account_move_line amlcf
Expand Down Expand Up @@ -133,7 +142,8 @@ def _revaluation_query(self, revaluation_date, start_date=None):
+ where_clause
+ """
GROUP BY
aat.type, aml.id
acc.account_type,
aml.id
HAVING
aml.amount_residual_currency <> 0
)
Expand Down
56 changes: 50 additions & 6 deletions l10n_th_multicurrency_revaluation/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ class ResCompany(models.Model):
string="Revaluation loss account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
(
"account_type",
"not in",
[
"asset_receivable",
"asset_cash",
"liability_payable",
"liability_credit_card",
],
),
("deprecated", "=", False),
],
)
Expand All @@ -21,7 +30,16 @@ class ResCompany(models.Model):
string="Revaluation gain account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
(
"account_type",
"not in",
[
"asset_receivable",
"asset_cash",
"liability_payable",
"liability_credit_card",
],
),
("deprecated", "=", False),
],
)
Expand All @@ -35,7 +53,16 @@ class ResCompany(models.Model):
string="Provision B.S. loss account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
(
"account_type",
"not in",
[
"asset_receivable",
"asset_cash",
"liability_payable",
"liability_credit_card",
],
),
("deprecated", "=", False),
],
)
Expand All @@ -44,7 +71,16 @@ class ResCompany(models.Model):
string="Provision B.S. gain account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
(
"account_type",
"not in",
[
"asset_receivable",
"asset_cash",
"liability_payable",
"liability_credit_card",
],
),
("deprecated", "=", False),
],
)
Expand All @@ -53,7 +89,6 @@ class ResCompany(models.Model):
string="Provision P&L loss account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
("deprecated", "=", False),
],
)
Expand All @@ -62,7 +97,16 @@ class ResCompany(models.Model):
string="Provision P&L gain account",
domain=lambda self: [
("company_id", "=", self.env.company.id),
("internal_type", "=", "other"),
(
"account_type",
"not in",
[
"asset_receivable",
"asset_cash",
"liability_payable",
"liability_credit_card",
],
),
("deprecated", "=", False),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Thai Localization - Multicurrency Revaluation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bc6f54addb32f0123e0587cadbbe83876b356e3f0e7463fefd623b0c171af945
!! source digest: sha256:bfff2b0ecdece89174d89c9407fd523021a5f79030c0487ee3dadbc070ce6557
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-thailand/tree/15.0/l10n_th_multicurrency_revaluation"><img alt="OCA/l10n-thailand" src="https://img.shields.io/badge/github-OCA%2Fl10n--thailand-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-thailand-15-0/l10n-thailand-15-0-l10n_th_multicurrency_revaluation"><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/l10n-thailand&amp;target_branch=15.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="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-thailand/tree/16.0/l10n_th_multicurrency_revaluation"><img alt="OCA/l10n-thailand" src="https://img.shields.io/badge/github-OCA%2Fl10n--thailand-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-thailand-16-0/l10n-thailand-16-0-l10n_th_multicurrency_revaluation"><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/l10n-thailand&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of the accounting module to
support the multicurrency and to allow you to generate automatically
revaluation journal entries.</p>
Expand Down Expand Up @@ -430,7 +430,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/l10n-thailand/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/l10n-thailand/issues/new?body=module:%20l10n_th_multicurrency_revaluation%0Aversion:%2015.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/l10n-thailand/issues/new?body=module:%20l10n_th_multicurrency_revaluation%0Aversion:%2016.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 @@ -470,7 +470,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
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/ps-tubtim"><img alt="ps-tubtim" src="https://github.com/ps-tubtim.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/l10n-thailand/tree/15.0/l10n_th_multicurrency_revaluation">OCA/l10n-thailand</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/l10n-thailand/tree/16.0/l10n_th_multicurrency_revaluation">OCA/l10n-thailand</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
Loading

0 comments on commit c42b372

Please sign in to comment.