Skip to content

Commit e67cda7

Browse files
[MIG] purchase_request_analytic: Migration to 17.0
1 parent 1829c07 commit e67cda7

File tree

9 files changed

+127
-100
lines changed

9 files changed

+127
-100
lines changed

purchase_request_analytic/README.rst

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Purchase Request Analytic
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:091f04d8f6a4d3c43d2c4472b26a68d8b4de7c34d58bc3e45bb3cb22b41b137d
10+
!! source digest: sha256:e5d542b4f36801b7d89139c82816d3daaeff1caff8abf8e095ff1f74f576d5d3
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,18 +17,19 @@ Purchase Request Analytic
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github
20-
:target: https://github.com/OCA/account-analytic/tree/17.0/purchase_request_analytic
20+
:target: https://github.com/OCA/account-analytic/tree/17.-/purchase_request_analytic
2121
:alt: OCA/account-analytic
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-purchase_request_analytic
23+
:target: https://translation.odoo-community.org/projects/account-analytic-17--/account-analytic-17---purchase_request_analytic
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=17.-
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
This module adds the analytic account field to Purchase Requests.
31+
This module adds an analytic distribution field to Purchase Requests.
32+
The field serves as a default for new lines on a request.
3233

3334
**Table of contents**
3435

@@ -38,8 +39,8 @@ This module adds the analytic account field to Purchase Requests.
3839
Usage
3940
=====
4041

41-
- Assign an analytic account to the purchase request or to purchase
42-
request lines.
42+
- Assign an analytic distribution to the purchase request or to
43+
purchase request lines.
4344

4445
Changelog
4546
=========
@@ -70,7 +71,7 @@ Bug Tracker
7071
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/issues>`_.
7172
In case of trouble, please check there if your issue has already been reported.
7273
If you spotted it first, help us to smash it by providing a detailed and welcomed
73-
`feedback <https://github.com/OCA/account-analytic/issues/new?body=module:%20purchase_request_analytic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
74+
`feedback <https://github.com/OCA/account-analytic/issues/new?body=module:%20purchase_request_analytic%0Aversion:%2017.-%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7475

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

@@ -102,6 +103,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
102103
mission is to support the collaborative development of Odoo features and
103104
promote its widespread use.
104105

105-
This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/17.0/purchase_request_analytic>`_ project on GitHub.
106+
This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/17.-/purchase_request_analytic>`_ project on GitHub.
106107

107108
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

purchase_request_analytic/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Purchase Request Analytic",
6-
"version": "15.0.1.0.1",
6+
"version": "17.0.1.0.0",
77
"author": "ForgeFlow, Odoo Community Association (OCA)",
88
"category": "Purchase Management",
99
"website": "https://github.com/OCA/account-analytic",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from odoo.tools.sql import column_exists
2+
3+
4+
def migrate(cr, version):
5+
"""Populate analytic distribution values from the old analytic account"""
6+
if column_exists(cr, "purchase_request", "analytic_distribution"):
7+
return
8+
cr.execute(
9+
"""
10+
ALTER TABLE purchase_request ADD COLUMN analytic_distribution jsonb;
11+
update purchase_request set analytic_distribution =
12+
json_build_object(analytic_account_id::varchar, 100.0)
13+
where analytic_account_id is not null;
14+
"""
15+
)

purchase_request_analytic/models/purchase_request.py

+19-30
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,37 @@
55

66

77
class PurchaseRequest(models.Model):
8-
_inherit = "purchase.request"
8+
_name = "purchase.request"
9+
_inherit = ["analytic.mixin", "purchase.request"]
910

10-
analytic_account_id = fields.Many2one(
11-
compute="_compute_analytic_account_id",
12-
inverse="_inverse_analytic_account_id",
13-
comodel_name="account.analytic.account",
14-
string="Analytic Account",
15-
readonly=True,
16-
states={"draft": [("readonly", False)]},
17-
store=True,
18-
help="The analytic account related to a sales order.",
11+
analytic_distribution = fields.Json(
12+
inverse="_inverse_analytic_distribution",
13+
help="The default distribution for new lines on this request",
1914
)
2015

21-
@api.depends("line_ids.analytic_account_id")
22-
def _compute_analytic_account_id(self):
23-
"""If all purchase request lines have same analytic account set
24-
analytic_account_id
25-
"""
16+
@api.depends("line_ids.analytic_distribution")
17+
def _compute_analytic_distribution(self):
18+
"""Take the distribution that is already set on all of our lines."""
2619
for pr in self:
27-
al = pr.analytic_account_id
20+
al = pr.analytic_distribution
2821
if pr.line_ids:
29-
first_line_analytic_account_id = pr.line_ids[0].analytic_account_id
22+
first_line_analytic_distribution = pr.line_ids[0].analytic_distribution
3023
all_lines_same = all(
31-
prl.analytic_account_id == first_line_analytic_account_id
24+
prl.analytic_distribution == first_line_analytic_distribution
3225
for prl in pr.line_ids
3326
)
34-
# If all lines share the same analytic_account_id,
27+
# If all lines share the same analytic_distribution,
3528
# set it to the purchase request.
3629
if all_lines_same:
37-
pr.analytic_account_id = first_line_analytic_account_id
30+
pr.analytic_distribution = first_line_analytic_distribution
3831
continue
3932
for prl in pr.line_ids:
40-
if prl.analytic_account_id != al:
33+
if prl.analytic_distribution != al:
4134
al = False
4235
break
43-
pr.analytic_account_id = al
36+
pr.analytic_distribution = al
4437

45-
def _inverse_analytic_account_id(self):
46-
"""If analytic_account is set on PR, propagate it to all purchase
47-
request lines
48-
"""
49-
for pr in self:
50-
if pr.analytic_account_id:
51-
for line in pr.line_ids:
52-
line.analytic_account_id = pr.analytic_account_id.id
38+
def _inverse_analytic_distribution(self):
39+
"""Set this requests's distribution on all of its lines."""
40+
for pr in self.filtered("analytic_distribution"):
41+
pr.line_ids.analytic_distribution = pr.analytic_distribution
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
This module adds the analytic account field to Purchase Requests.
1+
This module adds an analytic distribution field to Purchase Requests. The field
2+
serves as a default for new lines on a request.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
- Assign an analytic account to the purchase request or to purchase
1+
- Assign an analytic distribution to the purchase request or to purchase
22
request lines.
3+

purchase_request_analytic/static/description/index.html

+15-11
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -366,10 +367,11 @@ <h1 class="title">Purchase Request Analytic</h1>
366367
!! This file is generated by oca-gen-addon-readme !!
367368
!! changes will be overwritten. !!
368369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369-
!! source digest: sha256:091f04d8f6a4d3c43d2c4472b26a68d8b4de7c34d58bc3e45bb3cb22b41b137d
370+
!! source digest: sha256:e5d542b4f36801b7d89139c82816d3daaeff1caff8abf8e095ff1f74f576d5d3
370371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371-
<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/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/account-analytic/tree/17.0/purchase_request_analytic"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-purchase_request_analytic"><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-analytic&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372-
<p>This module adds the analytic account field to Purchase Requests.</p>
372+
<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/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/account-analytic/tree/17.-/purchase_request_analytic"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-analytic-17--/account-analytic-17---purchase_request_analytic"><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-analytic&amp;target_branch=17.-"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373+
<p>This module adds an analytic distribution field to Purchase Requests.
374+
The field serves as a default for new lines on a request.</p>
373375
<p><strong>Table of contents</strong></p>
374376
<div class="contents local topic" id="contents">
375377
<ul class="simple">
@@ -393,8 +395,8 @@ <h1 class="title">Purchase Request Analytic</h1>
393395
<div class="section" id="usage">
394396
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
395397
<ul class="simple">
396-
<li>Assign an analytic account to the purchase request or to purchase
397-
request lines.</li>
398+
<li>Assign an analytic distribution to the purchase request or to
399+
purchase request lines.</li>
398400
</ul>
399401
</div>
400402
<div class="section" id="changelog">
@@ -421,7 +423,7 @@ <h1><a class="toc-backref" href="#toc-entry-7">Bug Tracker</a></h1>
421423
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-analytic/issues">GitHub Issues</a>.
422424
In case of trouble, please check there if your issue has already been reported.
423425
If you spotted it first, help us to smash it by providing a detailed and welcomed
424-
<a class="reference external" href="https://github.com/OCA/account-analytic/issues/new?body=module:%20purchase_request_analytic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
426+
<a class="reference external" href="https://github.com/OCA/account-analytic/issues/new?body=module:%20purchase_request_analytic%0Aversion:%2017.-%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
425427
<p>Do not contact contributors directly about support or help with technical issues.</p>
426428
</div>
427429
<div class="section" id="credits">
@@ -443,11 +445,13 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
443445
<div class="section" id="maintainers">
444446
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
445447
<p>This module is maintained by the OCA.</p>
446-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
448+
<a class="reference external image-reference" href="https://odoo-community.org">
449+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
450+
</a>
447451
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
448452
mission is to support the collaborative development of Odoo features and
449453
promote its widespread use.</p>
450-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-analytic/tree/17.0/purchase_request_analytic">OCA/account-analytic</a> project on GitHub.</p>
454+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-analytic/tree/17.-/purchase_request_analytic">OCA/account-analytic</a> project on GitHub.</p>
451455
<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>
452456
</div>
453457
</div>

0 commit comments

Comments
 (0)