Skip to content

Commit

Permalink
[MIG] account_credit_control: Migrate patch
Browse files Browse the repository at this point in the history
Adapt imported patch OCA#86 to v13.

@Tecnativa TT24841
  • Loading branch information
Jairo Llopis authored and Naglis Jonaitis committed Jul 29, 2021
1 parent 3d39e39 commit 6a3f516
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions account_credit_control/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Contributors
* Pedro M. Baeza
* Jairo Llopis

* Enric Tobella <[email protected]>

Maintainers
~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion account_credit_control/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Credit Control",
"version": "13.0.1.1.2",
"version": "13.0.2.0.0",
"author": "Camptocamp,"
"Odoo Community Association (OCA),"
"Okia,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

from openupgradelib import openupgrade

from odoo.tools.parse_version import parse_version


@openupgrade.migrate()
def migrate(env, version):
# Skip migration if 12.0.3 was already installed (migration was already run)
if parse_version("12.0.3.0.0") <= parse_version(version) < parse_version("13.0"):
return
# Update mail.template records for credit.control.communication
communication_model = env.ref(
"account_credit_control.model_credit_control_communication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

from openupgradelib import openupgrade

from odoo.tools.parse_version import parse_version


@openupgrade.migrate()
def migrate(env, version):
# Skip migration if 12.0.3 was already installed (migration was already run)
if parse_version("12.0.3.0.0") <= parse_version(version) < parse_version("13.0"):
return
# Preserve mail_message_id historic data from credit.control.line records
mail_message_legacy = openupgrade.get_legacy_name("mail_message_id")
openupgrade.copy_columns(
Expand Down
12 changes: 7 additions & 5 deletions account_credit_control/models/credit_control_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ def _get_credit_lines(
def _aggregate_credit_lines(self, lines):
""" Aggregate credit control line by partner, level, and currency
"""
comms = self.browse()
if not lines:
return comms
return []
sql = (
"SELECT distinct partner_id, policy_level_id, "
" credit_control_line.currency_id, "
Expand All @@ -157,14 +156,17 @@ def _aggregate_credit_lines(self, lines):
group["currency_id"],
group["company_id"],
)
company_currency = (
self.env["res.company"].browse(group["company_id"]).currency_id
company = (
self.env["res.company"].browse(group["company_id"])
if group["company_id"]
else self.env.company
)
company_currency = company.currency_id
data["credit_control_line_ids"] = [(6, 0, level_lines.ids)]
data["partner_id"] = group["partner_id"]
data["policy_level_id"] = group["policy_level_id"]
data["currency_id"] = group["currency_id"] or company_currency.id
data["company_id"] = group["company_id"]
data["company_id"] = group["company_id"] or company.id
datas.append(data)
return datas

Expand Down
1 change: 1 addition & 0 deletions account_credit_control/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<li>Jairo Llopis</li>
</ul>
</li>
<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down

0 comments on commit 6a3f516

Please sign in to comment.