Skip to content

Commit

Permalink
[MIG] procurement_mto_analytic: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Jul 9, 2024
1 parent ccc6c78 commit 48656ad
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 59 deletions.
12 changes: 6 additions & 6 deletions procurement_mto_analytic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Purchase Analytic (MTO)
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5422c8951e5b5e292bcb68881aac0c7296bd9abe57ed26b8eecf69b555fef59c
!! source digest: sha256:541299b9d83e8dca12c223d23e8d78357360045ca1f7272edd4f4120da984de7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Purchase Analytic (MTO)
: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/15.0/procurement_mto_analytic
:target: https://github.com/OCA/account-analytic/tree/16.0/procurement_mto_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-15-0/account-analytic-15-0-procurement_mto_analytic
:target: https://translation.odoo-community.org/projects/account-analytic-16-0/account-analytic-16-0-procurement_mto_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=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -74,7 +74,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:%20procurement_mto_analytic%0Aversion:%2015.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:%20procurement_mto_analytic%0Aversion:%2016.0%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 @@ -125,6 +125,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/15.0/procurement_mto_analytic>`_ project on GitHub.
This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/16.0/procurement_mto_analytic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 4 additions & 4 deletions procurement_mto_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

{
"name": "Purchase Analytic (MTO)",
"summary": "This module sets analytic account in purchase order line from "
"sale order analytic account",
"version": "15.0.1.0.0",
"summary": "This module sets analytic distribution in purchase order line from "
"sale order line analytic distribution",
"version": "16.0.1.0.0",
"category": "Analytic",
"license": "AGPL-3",
"author": "Tecnativa, VentorTech, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["sale_stock", "purchase_stock"],
"depends": ["purchase_stock", "sale_stock"],
"installable": True,
}
1 change: 0 additions & 1 deletion procurement_mto_analytic/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

from . import sale_order_line
from . import stock_move
from . import stock_rule
from . import purchase_order_line
32 changes: 31 additions & 1 deletion procurement_mto_analytic/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,35 @@ def _prepare_purchase_order_line_from_procurement(
)._prepare_purchase_order_line_from_procurement(
product_id, product_qty, product_uom, company_id, values, po
)
res["account_analytic_id"] = values.get("account_analytic_id", False)
res["analytic_distribution"] = values.get("analytic_distribution", False)
return res

def _find_candidate(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
):
lines = (
self.filtered(
lambda po_line: po_line.analytic_distribution
== values["analytic_distribution"]
)
if values.get("analytic_distribution")
else self
)
return super(PurchaseOrderLine, lines)._find_candidate(
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
)
4 changes: 2 additions & 2 deletions procurement_mto_analytic/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class SaleOrderLine(models.Model):

def _prepare_procurement_values(self, group_id=False):
res = super()._prepare_procurement_values(group_id)
res.update({"account_analytic_id": self.order_id.analytic_account_id.id})
res.update({"analytic_distribution": self.analytic_distribution})
return res

def _purchase_service_prepare_line_values(self, purchase_order, quantity=False):
res = super()._purchase_service_prepare_line_values(
purchase_order=purchase_order, quantity=quantity
)
res.update({"account_analytic_id": self.order_id.analytic_account_id.id})
res.update({"analytic_distribution": self.analytic_distribution})
return res
7 changes: 4 additions & 3 deletions procurement_mto_analytic/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class StockMove(models.Model):

def _prepare_procurement_values(self):
res = super()._prepare_procurement_values()
res.update(
{"account_analytic_id": self.group_id.sale_id.analytic_account_id.id}
)
analytic_distribution = self.sale_line_id.analytic_distribution
# Update the procurement values with analytic_distribution if it exists
if analytic_distribution:
res.update({"analytic_distribution": analytic_distribution})
return res
18 changes: 0 additions & 18 deletions procurement_mto_analytic/models/stock_rule.py

This file was deleted.

8 changes: 4 additions & 4 deletions procurement_mto_analytic/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Purchase Analytic (MTO)</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5422c8951e5b5e292bcb68881aac0c7296bd9abe57ed26b8eecf69b555fef59c
!! source digest: sha256:541299b9d83e8dca12c223d23e8d78357360045ca1f7272edd4f4120da984de7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/15.0/procurement_mto_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-15-0/account-analytic-15-0-procurement_mto_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=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></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/16.0/procurement_mto_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-16-0/account-analytic-16-0-procurement_mto_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=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module takes account analytic value from sale order to the created
purchase order line.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -426,7 +426,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:%20procurement_mto_analytic%0Aversion:%2015.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:%20procurement_mto_analytic%0Aversion:%2016.0%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 Down Expand Up @@ -472,7 +472,7 @@ <h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<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/15.0/procurement_mto_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/16.0/procurement_mto_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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class TestPurchaseProcurementAnalytic(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseProcurementAnalytic, cls).setUpClass()
vendor = cls.env["res.partner"].create({"name": "Partner #2"})
supplierinfo = cls.env["product.supplierinfo"].create({"name": vendor.id})
cls.vendor = cls.env["res.partner"].create({"name": "Partner #2"})
supplierinfo = cls.env["product.supplierinfo"].create(
{"partner_id": cls.vendor.id}
)
mto = cls.env.ref("stock.route_warehouse0_mto")
mto.write({"active": True})
buy = cls.env.ref("purchase_stock.route_warehouse0_buy")
Expand All @@ -22,7 +24,7 @@ def setUpClass(cls):
}
)
supplierinfo_service = cls.env["product.supplierinfo"].create(
{"name": vendor.id}
{"partner_id": cls.vendor.id}
)
cls.service_product = cls.env["product.product"].create(
{
Expand All @@ -33,15 +35,14 @@ def setUpClass(cls):
}
)
cls.partner = cls.env["res.partner"].create({"name": "Partner #1"})
cls.analytic_distribution = dict(
{str(cls.env.ref("analytic.analytic_agrolait").id): 100.0}
)

def test_sale_to_procurement(self):
analytic_account = self.env["account.analytic.account"].create(
{"name": "Test Analytic Account"}
)
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"analytic_account_id": analytic_account.id,
"order_line": [
(
0,
Expand All @@ -51,36 +52,36 @@ def test_sale_to_procurement(self):
"product_uom_qty": 1,
"price_unit": self.product.list_price,
"name": self.product.name,
"analytic_distribution": self.analytic_distribution,
},
)
],
"picking_policy": "direct",
}
)
sale_order.with_context(test_enabled=True).action_confirm()

purchase_order = self.env["purchase.order.line"].search(
[("account_analytic_id", "=", analytic_account.id)]
purchase_order_line = self.env["purchase.order.line"].search(
[("partner_id", "=", self.vendor.id)]
)
self.assertTrue(purchase_order_line)
self.assertEqual(
purchase_order_line.analytic_distribution, self.analytic_distribution
)
self.assertTrue(purchase_order)

def test_sale_service_product(self):
analytic_account = self.env["account.analytic.account"].create(
{"name": "Test Service Analytic Account"}
)
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"analytic_account_id": analytic_account.id,
"order_line": [
(
0,
0,
{
"product_id": self.service_product.id,
"product_uom_qty": 1,
"price_unit": self.product.list_price,
"name": self.product.name,
"price_unit": self.service_product.list_price,
"name": self.service_product.name,
"analytic_distribution": self.analytic_distribution,
},
)
],
Expand All @@ -89,7 +90,10 @@ def test_sale_service_product(self):
)
sale_order.with_context(test_enabled=True).action_confirm()

purchase_order = self.env["purchase.order.line"].search(
[("account_analytic_id", "=", analytic_account.id)]
purchase_order_line = self.env["purchase.order.line"].search(
[("partner_id", "=", self.vendor.id)]
)
self.assertTrue(purchase_order_line)
self.assertTrue(
purchase_order_line.analytic_distribution, self.analytic_distribution
)
self.assertTrue(purchase_order)

0 comments on commit 48656ad

Please sign in to comment.