Skip to content

Commit f7c4b5c

Browse files
committed
[MIG] contract: Remove analytic_account_id and add migration
1 parent 4924db5 commit f7c4b5c

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

Diff for: contract/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Recurring - Contracts Management
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:19d8f78874c9775e7c788c7eed046d74ff47c6b86acb42ce1e80aeb905eed3c7
10+
!! source digest: sha256:08650aaf9f41e3d6c539cc52fdb02a84ad85f7bf3cdb4f63ebbd561f443bdd04
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png

Diff for: contract/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
{
1313
"name": "Recurring - Contracts Management",
14-
"version": "16.0.1.1.3",
14+
"version": "16.0.2.0.0",
1515
"category": "Contract Management",
1616
"license": "AGPL-3",
1717
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",

Diff for: contract/migrations/16.0.2.0.0/pre-migrate.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# © 2023 initOS GmbH
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
import json
5+
import logging
6+
7+
_logger = logging.getLogger(__name__)
8+
9+
10+
def migrate(cr, version):
11+
"""Migrate analytic account from contract line to analytic distribution"""
12+
13+
_logger.info("Migrating analytic distribution for contract.line")
14+
cr.execute(
15+
"""
16+
SELECT id, analytic_account_id, analytic_distribution
17+
FROM contract_line
18+
WHERE analytic_account_id IS NOT NULL
19+
"""
20+
)
21+
for line_id, analytic_account_id, analytic_distribution in cr.fetchall():
22+
analytic_account_id = str(analytic_account_id)
23+
if analytic_distribution:
24+
analytic_distribution[analytic_account_id] = (
25+
analytic_distribution.get(analytic_account_id, 0) + 100
26+
)
27+
else:
28+
analytic_distribution = {analytic_account_id: 100}
29+
30+
cr.execute(
31+
"UPDATE contract_line SET analytic_distribution = %s WHERE id = %s",
32+
(json.dumps(analytic_distribution), line_id),
33+
)

Diff for: contract/models/contract_line.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class ContractLine(models.Model):
3333
ondelete="cascade",
3434
)
3535
currency_id = fields.Many2one(related="contract_id.currency_id")
36-
analytic_account_id = fields.Many2one(
37-
string="Analytic account",
38-
comodel_name="account.analytic.account",
39-
)
4036
date_start = fields.Date(required=True)
4137
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
4238
termination_notice_date = fields.Date(
@@ -559,24 +555,12 @@ def _prepare_invoice_line(self):
559555
self.last_date_invoiced, self.recurring_next_date
560556
)
561557
name = self._insert_markers(dates[0], dates[1])
562-
563-
analytic_distribution = self.analytic_distribution
564-
analytic_account_id = self.analytic_account_id.id
565-
if analytic_account_id:
566-
analytic_account_id = str(analytic_account_id)
567-
if analytic_distribution:
568-
analytic_distribution[analytic_account_id] = (
569-
analytic_distribution.get(analytic_account_id, 0) + 100
570-
)
571-
else:
572-
analytic_distribution = {analytic_account_id: 100}
573-
574558
return {
575559
"quantity": self._get_quantity_to_invoice(*dates),
576560
"product_uom_id": self.uom_id.id,
577561
"discount": self.discount,
578562
"contract_line_id": self.id,
579-
"analytic_distribution": analytic_distribution,
563+
"analytic_distribution": self.analytic_distribution,
580564
"sequence": self.sequence,
581565
"name": name,
582566
"price_unit": self.price_unit,

Diff for: contract/static/description/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ <h1 class="title">Recurring - Contracts Management</h1>
366366
!! This file is generated by oca-gen-addon-readme !!
367367
!! changes will be overwritten. !!
368368
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369-
!! source digest: sha256:19d8f78874c9775e7c788c7eed046d74ff47c6b86acb42ce1e80aeb905eed3c7
369+
!! source digest: sha256:08650aaf9f41e3d6c539cc52fdb02a84ad85f7bf3cdb4f63ebbd561f443bdd04
370370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371371
<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>
372372
<p>This module enables contracts management with recurring

Diff for: contract/views/contract.xml

-10
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,6 @@
216216
invisible="1"
217217
/>
218218
<field name="name" widget="section_and_note_text" />
219-
<field
220-
name="analytic_account_id"
221-
groups="analytic.group_analytic_accounting"
222-
optional="hide"
223-
/>
224219
<field
225220
name="analytic_distribution"
226221
widget="analytic_distribution"
@@ -321,11 +316,6 @@
321316
<field name="sequence" widget="handle" />
322317
<field name="product_id" />
323318
<field name="name" widget="section_and_note_text" />
324-
<field
325-
name="analytic_account_id"
326-
groups="analytic.group_analytic_accounting"
327-
optional="hide"
328-
/>
329319
<field
330320
name="analytic_distribution"
331321
widget="analytic_distribution"

Diff for: contract/views/contract_line.xml

-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747
groups="analytic.group_analytic_accounting"
4848
attrs="{'invisible': [('display_type', '!=', False)]}"
4949
>
50-
<field
51-
name="analytic_account_id"
52-
groups="analytic.group_analytic_accounting"
53-
/>
5450
<field
5551
name="analytic_distribution"
5652
widget="analytic_distribution"
@@ -102,10 +98,6 @@
10298
<field name="sequence" widget="handle" />
10399
<field name="product_id" />
104100
<field name="name" />
105-
<field
106-
name="analytic_account_id"
107-
groups="analytic.group_analytic_accounting"
108-
/>
109101
<field
110102
name="analytic_distribution"
111103
widget="analytic_distribution"

0 commit comments

Comments
 (0)