Skip to content

Commit

Permalink
[MIG] contract: Remove analytic_account_id and add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
fkantelberg committed Jan 5, 2024
1 parent 4924db5 commit f7c4b5c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Recurring - Contracts Management
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:19d8f78874c9775e7c788c7eed046d74ff47c6b86acb42ce1e80aeb905eed3c7
!! source digest: sha256:08650aaf9f41e3d6c539cc52fdb02a84ad85f7bf3cdb4f63ebbd561f443bdd04
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down
2 changes: 1 addition & 1 deletion contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{
"name": "Recurring - Contracts Management",
"version": "16.0.1.1.3",
"version": "16.0.2.0.0",
"category": "Contract Management",
"license": "AGPL-3",
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
Expand Down
33 changes: 33 additions & 0 deletions contract/migrations/16.0.2.0.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# © 2023 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json
import logging

_logger = logging.getLogger(__name__)


def migrate(cr, version):
"""Migrate analytic account from contract line to analytic distribution"""

_logger.info("Migrating analytic distribution for contract.line")
cr.execute(
"""
SELECT id, analytic_account_id, analytic_distribution
FROM contract_line
WHERE analytic_account_id IS NOT NULL
"""
)
for line_id, analytic_account_id, analytic_distribution in cr.fetchall():
analytic_account_id = str(analytic_account_id)
if analytic_distribution:
analytic_distribution[analytic_account_id] = (
analytic_distribution.get(analytic_account_id, 0) + 100
)
else:
analytic_distribution = {analytic_account_id: 100}

cr.execute(
"UPDATE contract_line SET analytic_distribution = %s WHERE id = %s",
(json.dumps(analytic_distribution), line_id),
)
18 changes: 1 addition & 17 deletions contract/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class ContractLine(models.Model):
ondelete="cascade",
)
currency_id = fields.Many2one(related="contract_id.currency_id")
analytic_account_id = fields.Many2one(
string="Analytic account",
comodel_name="account.analytic.account",
)
date_start = fields.Date(required=True)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
termination_notice_date = fields.Date(
Expand Down Expand Up @@ -559,24 +555,12 @@ def _prepare_invoice_line(self):
self.last_date_invoiced, self.recurring_next_date
)
name = self._insert_markers(dates[0], dates[1])

analytic_distribution = self.analytic_distribution
analytic_account_id = self.analytic_account_id.id
if analytic_account_id:
analytic_account_id = str(analytic_account_id)
if analytic_distribution:
analytic_distribution[analytic_account_id] = (
analytic_distribution.get(analytic_account_id, 0) + 100
)
else:
analytic_distribution = {analytic_account_id: 100}

return {
"quantity": self._get_quantity_to_invoice(*dates),
"product_uom_id": self.uom_id.id,
"discount": self.discount,
"contract_line_id": self.id,
"analytic_distribution": analytic_distribution,
"analytic_distribution": self.analytic_distribution,
"sequence": self.sequence,
"name": name,
"price_unit": self.price_unit,
Expand Down
2 changes: 1 addition & 1 deletion contract/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h1 class="title">Recurring - Contracts Management</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:19d8f78874c9775e7c788c7eed046d74ff47c6b86acb42ce1e80aeb905eed3c7
!! source digest: sha256:08650aaf9f41e3d6c539cc52fdb02a84ad85f7bf3cdb4f63ebbd561f443bdd04
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/contract/tree/16.0/contract"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract"><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/contract&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 enables contracts management with recurring
Expand Down
10 changes: 0 additions & 10 deletions contract/views/contract.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@
invisible="1"
/>
<field name="name" widget="section_and_note_text" />
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
optional="hide"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
Expand Down Expand Up @@ -321,11 +316,6 @@
<field name="sequence" widget="handle" />
<field name="product_id" />
<field name="name" widget="section_and_note_text" />
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
optional="hide"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
Expand Down
8 changes: 0 additions & 8 deletions contract/views/contract_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
groups="analytic.group_analytic_accounting"
attrs="{'invisible': [('display_type', '!=', False)]}"
>
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
Expand Down Expand Up @@ -102,10 +98,6 @@
<field name="sequence" widget="handle" />
<field name="product_id" />
<field name="name" />
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
Expand Down

0 comments on commit f7c4b5c

Please sign in to comment.