Skip to content

Commit

Permalink
[MIG] product_form_sale_link: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Jan 13, 2025
1 parent 175f9d2 commit b193b43
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 21 deletions.
13 changes: 7 additions & 6 deletions product_form_sale_link/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Product Form Sale Link
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/17.0/product_form_sale_link
:target: https://github.com/OCA/sale-workflow/tree/18.0/product_form_sale_link
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-product_form_sale_link
:target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-product_form_sale_link
: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/sale-workflow&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -53,7 +53,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20product_form_sale_link%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20product_form_sale_link%0Aversion:%2018.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 All @@ -68,7 +68,8 @@ Authors
Contributors
------------

- Denis Roussel <[email protected]>
- Denis Roussel <[email protected]>
- Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>

Maintainers
-----------
Expand All @@ -83,6 +84,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/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/product_form_sale_link>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/18.0/product_form_sale_link>`_ 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 product_form_sale_link/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Product Form Sale Link",
"summary": """
Adds a button on product forms to access Sale Lines""",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"category": "Sales",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
Expand Down
9 changes: 5 additions & 4 deletions product_form_sale_link/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
class ProductProduct(models.Model):
_inherit = "product.product"

sale_lines_count = fields.Integer(
compute="_compute_sale_lines_count", string="Sales"
)
sale_lines_count = fields.Integer(compute="_compute_sale_lines_count")

def _compute_sale_lines_count(self):
if not self.user_has_groups("sales_team.group_sale_salesman") or not self.ids:
if (
not self.env.user.has_group("sales_team.group_sale_salesman")
or not self.ids
):
self.sale_lines_count = 0.0
return
domain = [
Expand Down
2 changes: 1 addition & 1 deletion product_form_sale_link/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ProductTemplate(models.Model):
_inherit = "product.template"

sale_lines_count = fields.Float(compute="_compute_sale_lines_count", string="Sales")
sale_lines_count = fields.Float(compute="_compute_sale_lines_count")

@api.depends("product_variant_ids.sale_lines_count")
def _compute_sale_lines_count(self):
Expand Down
1 change: 1 addition & 0 deletions product_form_sale_link/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Denis Roussel \<<[email protected]>\>
- Heliconia Solutions Pvt. Ltd. \<<https://www.heliconia.io>\>
18 changes: 11 additions & 7 deletions product_form_sale_link/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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 @@ -368,7 +369,7 @@ <h1 class="title">Product Form Sale Link</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:23b543040af6c40e5edbffd9663874b0ce7a507a25b4c0075e1ad4790931595d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/sale-workflow/tree/17.0/product_form_sale_link"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-product_form_sale_link"><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/sale-workflow&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><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/sale-workflow/tree/18.0/product_form_sale_link"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-product_form_sale_link"><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/sale-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a button on product forms with a link to sale order
lines for that product.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -395,7 +396,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20product_form_sale_link%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/sale-workflow/issues/new?body=module:%20product_form_sale_link%0Aversion:%2018.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 All @@ -410,16 +411,19 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Denis Roussel &lt;<a class="reference external" href="mailto:denis.roussel&#64;acsone.eu">denis.roussel&#64;acsone.eu</a>&gt;</li>
<li>Heliconia Solutions Pvt. Ltd. &lt;<a class="reference external" href="https://www.heliconia.io">https://www.heliconia.io</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">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/sale-workflow/tree/17.0/product_form_sale_link">OCA/sale-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/18.0/product_form_sale_link">OCA/sale-workflow</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
1 change: 1 addition & 0 deletions product_form_sale_link/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_product
172 changes: 172 additions & 0 deletions product_form_sale_link/tests/test_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
from odoo.tests import TransactionCase, tagged


@tagged("post_install", "-at_install")
class TestProductSalesCount(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

# Create test users with different access rights
sale_manager_group = cls.env.ref("sales_team.group_sale_manager")
sale_user_group = cls.env.ref("sales_team.group_sale_salesman")
product_manager_group = cls.env.ref("product.group_product_manager")

cls.user_salesman = cls.env["res.users"].create(
{
"name": "Test Salesman",
"login": "test_salesman",
"email": "[email protected]",
"groups_id": [
(
6,
0,
[
sale_manager_group.id,
sale_user_group.id,
cls.env.ref("base.group_user").id,
cls.env.ref("base.group_partner_manager").id,
],
)
],
}
)

cls.user_employee = cls.env["res.users"].create(
{
"name": "Test Employee",
"login": "test_employee",
"email": "[email protected]",
"groups_id": [
(
6,
0,
[
cls.env.ref("base.group_user").id,
product_manager_group.id,
],
)
],
}
)

cls.currency = cls.env["res.currency"].create(
{
"name": "Test Currency",
"symbol": "T€",
"rate": 1.0,
}
)

cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "Test Pricelist",
"currency_id": cls.currency.id,
}
)

cls.product_template = cls.env["product.template"].create(
{
"name": "Test Product Template",
"list_price": 100.0,
"taxes_id": False,
"currency_id": cls.currency.id,
}
)

cls.size_attribute = cls.env["product.attribute"].create(
{
"name": "Size",
"create_variant": "always",
}
)

cls.size_s = cls.env["product.attribute.value"].create(
{
"name": "S",
"attribute_id": cls.size_attribute.id,
}
)

cls.size_m = cls.env["product.attribute.value"].create(
{
"name": "M",
"attribute_id": cls.size_attribute.id,
}
)

cls.env["product.template.attribute.line"].create(
{
"product_tmpl_id": cls.product_template.id,
"attribute_id": cls.size_attribute.id,
"value_ids": [(6, 0, [cls.size_s.id, cls.size_m.id])],
}
)

cls.product_variant1, cls.product_variant2 = (
cls.product_template.product_variant_ids
)

cls.partner = cls.env["res.partner"].create(
{
"name": "Test Partner",
"email": "[email protected]",
}
)

cls.sale_order = cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
"pricelist_id": cls.pricelist.id,
}
)

def test_product_variant_sales_count_with_salesman(self):
"""Test sales count computation for product variants with salesman access"""
self.sale_order.action_confirm()

# Switch to salesman user and check counts
product = self.product_variant1.with_user(self.user_salesman)
product._compute_sale_lines_count()

self.assertEqual(product.sale_lines_count, 1)
self.assertEqual(
self.product_variant2.with_user(self.user_salesman).sale_lines_count, 0
)

def test_product_variant_sales_count_without_access(self):
"""Test sales count computation for product variants without salesman access"""

self.sale_order.action_confirm()

# Switch to employee user and check counts
product = self.product_variant1.with_user(self.user_employee)
product._compute_sale_lines_count()

self.assertEqual(product.sale_lines_count, 0)

def test_product_template_sales_count(self):
"""Test sales count computation for product template"""
self.env["sale.order.line"].create(
[
{
"order_id": self.sale_order.id,
"product_id": self.product_variant1.id,
"product_uom_qty": 1.0,
"price_unit": 100.0,
},
{
"order_id": self.sale_order.id,
"product_id": self.product_variant2.id,
"product_uom_qty": 1.0,
"price_unit": 100.0,
},
]
)

self.sale_order.action_confirm()

template = self.product_template.with_user(self.user_salesman)
template._compute_sale_lines_count()

self.assertEqual(template.sale_lines_count, 2)
2 changes: 1 addition & 1 deletion product_form_sale_link/views/product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
groups="sales_team.group_sale_salesman"
invisible="not sale_ok"
>
<field name="sale_lines_count" widget="statinfo" />
<field name="sale_lines_count" widget="statinfo" string="Sales" />
</button>
</button>
</field>
Expand Down
2 changes: 1 addition & 1 deletion product_form_sale_link/views/product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
groups="sales_team.group_sale_salesman"
invisible="not sale_ok"
>
<field name="sale_lines_count" widget="statinfo" />
<field name="sale_lines_count" widget="statinfo" string="Sales" />
</button>
</div>
</field>
Expand Down

0 comments on commit b193b43

Please sign in to comment.