Skip to content

[17.0][MIG] purchase_analytic_global: Migration to 17.0 #2668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: 17.0
Choose a base branch
from

Conversation

Luca-Policastro
Copy link

@Luca-Policastro Luca-Policastro commented May 6, 2025

Migration done from #2393

guewen and others added 21 commits May 6, 2025 14:30
An analytic account field on the purchase order that applies the
account on all the lines of the purchase order.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: purchase-workflow-14.0/purchase-workflow-14.0-purchase_analytic_global
Translate-URL: https://translation.odoo-community.org/projects/purchase-workflow-14-0/purchase-workflow-14-0-purchase_analytic_global/
Currently translated at 100.0% (3 of 3 strings)

Translation: purchase-workflow-15.0/purchase-workflow-15.0-purchase_analytic_global
Translate-URL: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_analytic_global/es/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: purchase-workflow-15.0/purchase-workflow-15.0-purchase_analytic_global
Translate-URL: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_analytic_global/
@Luca-Policastro Luca-Policastro force-pushed the 17.0-mig-purchase_analytic_global branch from 6988300 to 4d1247f Compare May 6, 2025 14:51
Comment on lines 20 to 31
def _compute_analytic_distribution(self):
"""If all order line have same analytic distribution set analytic_distribution.
If no lines, respect value given by the user.
"""
for rec in self:
if rec.order_line:
al = rec.order_line[0].analytic_distribution or False
for ol in rec.order_line:
if ol.analytic_distribution != al:
al = False
break
rec.analytic_distribution = al
Copy link
Contributor

@yankinmax yankinmax May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello @Luca-Policastro
what do you think about such an approach from v18 solving the same issue:
https://github.com/OCA/purchase-workflow/blob/18.0/purchase_analytic_global/models/purchase_order.py

Copy link
Contributor

@SilvioC2C SilvioC2C left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the last 2 commits

Comment on lines 24 to 31
for rec in self:
if rec.order_line:
al = rec.order_line[0].analytic_distribution or False
for ol in rec.order_line:
if ol.analytic_distribution != al:
al = False
break
rec.analytic_distribution = al
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for rec in self:
if rec.order_line:
al = rec.order_line[0].analytic_distribution or False
for ol in rec.order_line:
if ol.analytic_distribution != al:
al = False
break
rec.analytic_distribution = al
for po in self:
if lines := po.order_line:
distributions = set(ln.analytic_distribution for ln in lines)
if len(distributions) == 1:
po.analytic_distribution = tuple(distributions)[0]
else:
po.analytic_distribution = False

Comment on lines 40 to 47
@api.onchange("analytic_distribution")
def _onchange_analytic_distribution(self):
"""When change analytic_distribution
set analytic distribution on all order lines"""
if self.analytic_distribution:
self.order_line.update(
{"analytic_distribution": self.analytic_distribution}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this equivalent to the inverse method that's already in place?

@Luca-Policastro Luca-Policastro force-pushed the 17.0-mig-purchase_analytic_global branch from 4d1247f to 0e35cca Compare May 15, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.