Skip to content

Commit

Permalink
[MIG] purchase_request_analytic: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Jul 8, 2024
1 parent 1829c07 commit fcb7aeb
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 98 deletions.
19 changes: 10 additions & 9 deletions purchase_request_analytic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Purchase Request Analytic
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:091f04d8f6a4d3c43d2c4472b26a68d8b4de7c34d58bc3e45bb3cb22b41b137d
!! source digest: sha256:e5d542b4f36801b7d89139c82816d3daaeff1caff8abf8e095ff1f74f576d5d3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,18 +17,19 @@ Purchase Request Analytic
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github
:target: https://github.com/OCA/account-analytic/tree/17.0/purchase_request_analytic
:target: https://github.com/OCA/account-analytic/tree/17.-/purchase_request_analytic
:alt: OCA/account-analytic
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-purchase_request_analytic
:target: https://translation.odoo-community.org/projects/account-analytic-17--/account-analytic-17---purchase_request_analytic
: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/account-analytic&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=17.-
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

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

**Table of contents**

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

- Assign an analytic account to the purchase request or to purchase
request lines.
- Assign an analytic distribution to the purchase request or to
purchase request lines.

Changelog
=========
Expand Down Expand Up @@ -70,7 +71,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/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/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 <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**>`_.

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

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

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

{
"name": "Purchase Request Analytic",
"version": "15.0.1.0.1",
"version": "17.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"category": "Purchase Management",
"website": "https://github.com/OCA/account-analytic",
Expand Down
15 changes: 15 additions & 0 deletions purchase_request_analytic/migrations/16.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo.tools.sql import column_exists


def migrate(cr, version):
"""Populate analytic distribution values from the old analytic account"""
if column_exists(cr, "purchase_request", "analytic_distribution"):
return
cr.execute(
"""
ALTER TABLE purchase_request ADD COLUMN analytic_distribution jsonb;
update purchase_request set analytic_distribution =
json_build_object(analytic_account_id::varchar, 100.0)
where analytic_account_id is not null;
"""
)
49 changes: 19 additions & 30 deletions purchase_request_analytic/models/purchase_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,37 @@


class PurchaseRequest(models.Model):
_inherit = "purchase.request"
_name = "purchase.request"
_inherit = ["analytic.mixin", "purchase.request"]

analytic_account_id = fields.Many2one(
compute="_compute_analytic_account_id",
inverse="_inverse_analytic_account_id",
comodel_name="account.analytic.account",
string="Analytic Account",
readonly=True,
states={"draft": [("readonly", False)]},
store=True,
help="The analytic account related to a sales order.",
analytic_distribution = fields.Json(
inverse="_inverse_analytic_distribution",
help="The default distribution for new lines on this request",
)

@api.depends("line_ids.analytic_account_id")
def _compute_analytic_account_id(self):
"""If all purchase request lines have same analytic account set
analytic_account_id
"""
@api.depends("line_ids.analytic_distribution")
def _compute_analytic_distribution(self):
"""Take the distribution that is already set on all of our lines."""
for pr in self:
al = pr.analytic_account_id
al = pr.analytic_distribution
if pr.line_ids:
first_line_analytic_account_id = pr.line_ids[0].analytic_account_id
first_line_analytic_distribution = pr.line_ids[0].analytic_distribution
all_lines_same = all(
prl.analytic_account_id == first_line_analytic_account_id
prl.analytic_distribution == first_line_analytic_distribution
for prl in pr.line_ids
)
# If all lines share the same analytic_account_id,
# If all lines share the same analytic_distribution,
# set it to the purchase request.
if all_lines_same:
pr.analytic_account_id = first_line_analytic_account_id
pr.analytic_distribution = first_line_analytic_distribution
continue
for prl in pr.line_ids:
if prl.analytic_account_id != al:
if prl.analytic_distribution != al:
al = False
break
pr.analytic_account_id = al
pr.analytic_distribution = al

def _inverse_analytic_account_id(self):
"""If analytic_account is set on PR, propagate it to all purchase
request lines
"""
for pr in self:
if pr.analytic_account_id:
for line in pr.line_ids:
line.analytic_account_id = pr.analytic_account_id.id
def _inverse_analytic_distribution(self):
"""Set this requests's distribution on all of its lines."""
for pr in self.filtered("analytic_distribution"):
pr.line_ids.analytic_distribution = pr.analytic_distribution
3 changes: 2 additions & 1 deletion purchase_request_analytic/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module adds the analytic account field to Purchase Requests.
This module adds an analytic distribution field to Purchase Requests. The field
serves as a default for new lines on a request.
3 changes: 2 additions & 1 deletion purchase_request_analytic/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Assign an analytic account to the purchase request or to purchase
- Assign an analytic distribution to the purchase request or to purchase
request lines.

26 changes: 15 additions & 11 deletions purchase_request_analytic/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -366,10 +367,11 @@ <h1 class="title">Purchase Request Analytic</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:091f04d8f6a4d3c43d2c4472b26a68d8b4de7c34d58bc3e45bb3cb22b41b137d
!! source digest: sha256:e5d542b4f36801b7d89139c82816d3daaeff1caff8abf8e095ff1f74f576d5d3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<p>This module adds the analytic account field to Purchase Requests.</p>
<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>
<p>This module adds an analytic distribution field to Purchase Requests.
The field serves as a default for new lines on a request.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -393,8 +395,8 @@ <h1 class="title">Purchase Request Analytic</h1>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<ul class="simple">
<li>Assign an analytic account to the purchase request or to purchase
request lines.</li>
<li>Assign an analytic distribution to the purchase request or to
purchase request lines.</li>
</ul>
</div>
<div class="section" id="changelog">
Expand All @@ -421,7 +423,7 @@ <h1><a class="toc-backref" href="#toc-entry-7">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-analytic/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/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>
<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>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -443,11 +445,13 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<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>
<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>
<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 fcb7aeb

Please sign in to comment.