Skip to content

Commit

Permalink
Merge pull request #102 from OCA/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/product-pack (17.0)
  • Loading branch information
bt-admin authored Oct 30, 2024
2 parents c0bfb71 + 71fa9d2 commit 3021362
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[product_pack](product_pack/) | 17.0.1.0.0 | [![ernestotejeda](https://github.com/ernestotejeda.png?size=30px)](https://github.com/ernestotejeda) | This module allows you to set a product as a Pack
[sale_product_pack](sale_product_pack/) | 17.0.1.0.0 | [![ernestotejeda](https://github.com/ernestotejeda.png?size=30px)](https://github.com/ernestotejeda) | This module allows you to sell product packs
[sale_product_pack](sale_product_pack/) | 17.0.1.0.1 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | This module allows you to sell product packs
[website_sale_product_pack](website_sale_product_pack/) | 17.0.1.0.0 | | Compatibility module of product pack with e-commerce

[//]: # (end addons)
Expand Down
10 changes: 5 additions & 5 deletions sale_product_pack/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale Product Pack
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4bf918093776c52bc5c07ca25581fcec5d0031d35439b2492df93695471f989d
!! source digest: sha256:fa44591d6037f7b9eb135d0df8c32b2a06e73667371a13bbd151ff40bc0c2759
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -122,13 +122,13 @@ 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.

.. |maintainer-ernestotejeda| image:: https://github.com/ernestotejeda.png?size=40px
:target: https://github.com/ernestotejeda
:alt: ernestotejeda
.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px
:target: https://github.com/victoralmau
:alt: victoralmau

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ernestotejeda|
|maintainer-victoralmau|

This module is part of the `OCA/product-pack <https://github.com/OCA/product-pack/tree/17.0/sale_product_pack>`_ project on GitHub.

Expand Down
4 changes: 2 additions & 2 deletions sale_product_pack/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Product Pack",
"version": "17.0.1.0.0",
"version": "17.0.1.0.1",
"category": "Sales",
"summary": "This module allows you to sell product packs",
"website": "https://github.com/OCA/product-pack",
"author": "NaN·tic, ADHOC SA, Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"],
"maintainers": ["victoralmau"],
"license": "AGPL-3",
"depends": ["product_pack", "sale"],
"data": ["security/ir.model.access.csv", "views/product_pack_line_views.xml"],
Expand Down
26 changes: 15 additions & 11 deletions sale_product_pack/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ def expand_pack_line(self, write=False):

@api.model_create_multi
def create(self, vals_list):
new_vals = []
res = self.browse()
for elem in vals_list:
product = self.env["product.product"].browse(elem.get("product_id"))
if product and product.pack_ok and product.pack_type != "non_detailed":
"""Only when strictly necessary (a product is a pack) will be created line
by line, this is necessary to maintain the correct order.
"""
product_ids = [elem.get("product_id") for elem in vals_list]
products = self.env["product.product"].browse(product_ids)
if any(p.pack_ok and p.pack_type != "non_detailed" for p in products):
res = self.browse()
for elem in vals_list:
line = super().create([elem])
line.expand_pack_line()
res |= line
else:
new_vals.append(elem)
res |= super().create(new_vals)
return res
product = line.product_id
res += line
if product and product.pack_ok and product.pack_type != "non_detailed":
line.expand_pack_line()
return res
else:
return super().create(vals_list)

def write(self, vals):
res = super().write(vals)
Expand Down
15 changes: 9 additions & 6 deletions sale_product_pack/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 @@ -366,7 +367,7 @@ <h1 class="title">Sale Product Pack</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4bf918093776c52bc5c07ca25581fcec5d0031d35439b2492df93695471f989d
!! source digest: sha256:fa44591d6037f7b9eb135d0df8c32b2a06e73667371a13bbd151ff40bc0c2759
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/product-pack/tree/17.0/sale_product_pack"><img alt="OCA/product-pack" src="https://img.shields.io/badge/github-OCA%2Fproduct--pack-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-pack-17-0/product-pack-17-0-sale_product_pack"><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/product-pack&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 <em>Product Pack</em> functionality to sales orders. You can
Expand Down Expand Up @@ -462,12 +463,14 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">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>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/ernestotejeda"><img alt="ernestotejeda" src="https://github.com/ernestotejeda.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/victoralmau"><img alt="victoralmau" src="https://github.com/victoralmau.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-pack/tree/17.0/sale_product_pack">OCA/product-pack</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>
Expand Down
68 changes: 65 additions & 3 deletions sale_product_pack/tests/test_sale_product_pack.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase
from odoo.addons.base.tests.common import BaseCommon


class TestSaleProductPack(TransactionCase):
class TestSaleProductPack(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_do_not_expand(self):
pack_line_update = pack_line.with_context(update_pricelist=True)
self.assertTrue(pack_line_update.do_no_expand_pack_lines)

def test_create_several_lines(self):
def test_create_several_lines_01(self):
# Create two sale order lines with two pack products
# Check 8 lines are created
# Check lines sequences and order are respected
Expand Down Expand Up @@ -273,3 +273,65 @@ def test_create_several_lines(self):
self.assertEqual(sequence_tp, self.sale_order.order_line[5].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[6].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[7].sequence)

def test_create_several_lines_02(self):
# Create two sale order lines with pack product
# Check 5 lines are created
# Check lines sequences and order are respected
product_cp = self.env.ref("product_pack.product_pack_cpu_detailed_components")
product = self.env["product.product"].create({"name": "Test product"})
vals = [
{
"order_id": self.sale_order.id,
"name": product.name,
"product_id": product.id,
"product_uom_qty": 1,
},
{
"order_id": self.sale_order.id,
"name": product_cp.name,
"product_id": product_cp.id,
"product_uom_qty": 1,
},
]
self.env["sale.order.line"].create(vals)
# After create, there will be eight lines (1 + 4)
self.assertEqual(len(self.sale_order.order_line), 5)
# Check if lines are well ordered
self.assertEqual(self.sale_order.order_line[0].product_id, product)
self.assertEqual(self.sale_order.order_line[1].product_id, product_cp)
sequence_tp = self.sale_order.order_line[1].sequence
self.assertEqual(sequence_tp, self.sale_order.order_line[2].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[3].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[4].sequence)

def test_create_several_lines_03(self):
# Create two sale order lines with pack product
# Check 5 lines are created
# Check lines sequences and order are respected
product_cp = self.env.ref("product_pack.product_pack_cpu_detailed_components")
product = self.env["product.product"].create({"name": "Test product"})
vals = [
{
"order_id": self.sale_order.id,
"name": product_cp.name,
"product_id": product_cp.id,
"product_uom_qty": 1,
},
{
"order_id": self.sale_order.id,
"name": product.name,
"product_id": product.id,
"product_uom_qty": 1,
},
]
self.env["sale.order.line"].create(vals)
# After create, there will be eight lines (4 + 1)
self.assertEqual(len(self.sale_order.order_line), 5)
# Check if lines are well ordered
self.assertEqual(self.sale_order.order_line[0].product_id, product_cp)
sequence_tp = self.sale_order.order_line[0].sequence
self.assertEqual(sequence_tp, self.sale_order.order_line[1].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[2].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[3].sequence)
self.assertEqual(self.sale_order.order_line[4].product_id, product)

0 comments on commit 3021362

Please sign in to comment.