Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const config = [{
},

}, {
files: ["**/*.esm.js"],
files: ["**/*.esm.js", "**/*test.js"],

languageOptions: {
ecmaVersion: 2024,
Expand Down
13 changes: 8 additions & 5 deletions sale_product_pack/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=================
Sale Product Pack
=================
Expand All @@ -17,7 +13,7 @@ Sale Product Pack
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--pack-lightgray.png?logo=github
Expand Down Expand Up @@ -88,6 +84,7 @@ Authors
* NaN·tic
* ADHOC SA
* Tecnativa
* ACSONE SA/NV

Contributors
------------
Expand All @@ -108,13 +105,19 @@ Contributors
- `Acsone <https://www.acsone.eu/>`__:

- Maxime Franco
- Stéphane Mangin <stephane.mangin@acsone.eu>

- `ADHOC SA <https://www.adhoc.com.ar>`__:

- Bruno Zanotti
- Augusto Weiss
- Nicolas Col

- `Atrium res
Informatica <https://www.malt.fr/profile/stephanemangin>`__

- Stéphane Mangin <stephane.mangin@webmel.com>

Maintainers
-----------

Expand Down
14 changes: 12 additions & 2 deletions sale_product_pack/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright 2019 NaN (http://www.nan-tic.com) - Àngel Àlvarez
# Copyright 2026 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Product Pack",
"version": "18.0.1.0.2",
"version": "18.0.1.1.0",
"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)",
"author": "NaN·tic, ADHOC SA, Tecnativa, ACSONE SA/NV,"
" Odoo Community Association (OCA)",
"maintainers": ["victoralmau"],
"license": "AGPL-3",
"depends": ["product_pack", "sale"],
Expand All @@ -15,5 +17,13 @@
"demo/product_pack_line_demo.xml",
"demo/sale_pack_demo.xml",
],
"assets": {
"web.assets_backend": [
"sale_product_pack/static/src/js/**/*.js",
],
"web.assets_unit_tests": [
"sale_product_pack/static/tests/sale_order_line.esm.test.js",
],
},
"installable": True,
}
40 changes: 15 additions & 25 deletions sale_product_pack/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, models
from odoo.exceptions import UserError
from odoo import models


class SaleOrder(models.Model):
Expand All @@ -13,34 +12,20 @@ def copy(self, default=None):
pack_copied_lines = sale_copy.order_line.filtered(
lambda line: line.pack_parent_line_id.order_id == self
)
pack_copied_lines.unlink()
pack_copied_lines.with_context(pack_children_force_unlink=True).unlink()
return sale_copy

@api.onchange("order_line")
def check_pack_line_unlink(self):
"""At least on embeded tree editable view odoo returns a recordset on
_origin.order_line only when lines are unlinked and this is exactly
what we need
"""
origin_line_ids = self._origin.order_line.ids
line_ids = self.order_line.ids
removed_line_ids = list(set(origin_line_ids) - set(line_ids))
removed_line = self.env["sale.order.line"].browse(removed_line_ids)
if removed_line.filtered(
lambda x: x.pack_parent_line_id
and not x.pack_parent_line_id.product_id.pack_modifiable
):
raise UserError(
_(
"You cannot delete this line because is part of a pack in"
" this sale order. In order to delete this line you need to"
" delete the pack itself"
)
)

def write(self, vals):
pack_parent_delete_ids = []
if "order_line" in vals:
to_delete_ids = [e[1] for e in vals["order_line"] if e[0] == 2]
if to_delete_ids:
pack_parent_delete_ids = (
self.env["sale.order.line"]
.browse(to_delete_ids)
.filtered(lambda line: line.pack_child_line_ids)
.ids
)
subpacks_to_delete_ids = (
self.env["sale.order.line"]
.search(
Expand All @@ -56,6 +41,11 @@ def write(self, vals):
subpacks_to_delete_ids.remove(cmd[1])
for to_delete_id in subpacks_to_delete_ids:
vals["order_line"].append([2, to_delete_id, False])
if pack_parent_delete_ids:
return super(
SaleOrder,
self.with_context(pack_parent_delete_ids=pack_parent_delete_ids),
).write(vals)
return super().write(vals)

def _get_update_prices_lines(self):
Expand Down
47 changes: 36 additions & 11 deletions sale_product_pack/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from odoo.exceptions import UserError
from odoo.fields import first

IMMUTABLE_CHILD_FIELDS = [
"product_id",
"product_uom_qty",
"product_uom",
"price_unit",
"discount",
"name",
"tax_id",
]


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
Expand Down Expand Up @@ -100,22 +110,37 @@ def write(self, vals):
record.expand_pack_line(write=True)
return res

@api.onchange(
"product_id",
"product_uom_qty",
"product_uom",
"price_unit",
"discount",
"name",
"tax_id",
)
def unlink(self):
# Avoid removing of a component line if the parent line is not also being
# removed and the pack is not modifiable
forcing_context = self.env.context.get("pack_children_force_unlink", False)
pack_parent_delete_ids = self.env.context.get("pack_parent_delete_ids", [])
if not forcing_context and self.filtered(
lambda x: x.pack_parent_line_id
and x.pack_parent_line_id.id not in pack_parent_delete_ids
and (
x.pack_parent_line_id not in self
or x.pack_parent_line_id in x.order_id.order_line
)
and not x.pack_parent_line_id.product_id.pack_modifiable
):
raise UserError(
_(
"You cannot delete this line because it is part of a pack in"
" this sale order. In order to delete this line you need to"
" delete the pack itself."
)
)
return super().unlink()

@api.onchange(*IMMUTABLE_CHILD_FIELDS)
def check_pack_line_modify(self):
"""Do not let to edit a sale order line if this one belongs to pack"""
if self._origin.pack_parent_line_id and not self._origin.pack_modifiable:
raise UserError(
_(
"You can not change this line because is part of a pack"
" included in this order"
"You can not change this line because it is part of a pack"
" included in this order."
)
)

Expand Down
3 changes: 3 additions & 0 deletions sale_product_pack/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
- Daniel Reis \<<dreis@opensourceintegrators.com>\>
- [Acsone](https://www.acsone.eu/):
- Maxime Franco
- Stéphane Mangin \<<stephane.mangin@acsone.eu>\>
- [ADHOC SA](https://www.adhoc.com.ar):
- Bruno Zanotti
- Augusto Weiss
- Nicolas Col
- [Atrium res Informatica](https://www.malt.fr/profile/stephanemangin)
- Stéphane Mangin \<<stephane.mangin@webmel.com>\>
35 changes: 18 additions & 17 deletions sale_product_pack/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Sale Product Pack</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="sale-product-pack">
<h1 class="title">Sale Product Pack</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="sale-product-pack">
<h1>Sale Product Pack</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d0034cc2b56fe98dabcd701ddded4a3adc81775fbf8857041c8b9ebd13eeb6ad
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-pack/tree/18.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-18-0/product-pack-18-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=18.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/product-pack/tree/18.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-18-0/product-pack-18-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=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 <em>Product Pack</em> functionality to sales orders. You can
choose a <em>Pack</em> in <em>sales order lines</em> and see different behaviors
depending on “Pack type” and “Pack component price” fields options
Expand All @@ -394,7 +389,7 @@ <h1>Sale Product Pack</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to <em>Sales &gt; Products &gt; Products</em>, create or select a product and
Expand All @@ -412,7 +407,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>If this module is installed and stock module is installed too, when
you create a Sale order for a <em>Non detailed</em> Pack and you confirm it,
Expand All @@ -422,25 +417,26 @@ <h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-pack/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/product-pack/issues/new?body=module:%20sale_product_pack%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">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>NaN·tic</li>
<li>ADHOC SA</li>
<li>Tecnativa</li>
<li>ACSONE SA/NV</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Ernesto Tejeda</li>
Expand All @@ -457,6 +453,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</li>
<li><a class="reference external" href="https://www.acsone.eu/">Acsone</a>:<ul>
<li>Maxime Franco</li>
<li>Stéphane Mangin &lt;<a class="reference external" href="mailto:stephane.mangin&#64;acsone.eu">stephane.mangin&#64;acsone.eu</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.adhoc.com.ar">ADHOC SA</a>:<ul>
Expand All @@ -465,10 +462,15 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<li>Nicolas Col</li>
</ul>
</li>
<li><a class="reference external" href="https://www.malt.fr/profile/stephanemangin">Atrium res
Informatica</a><ul>
<li>Stéphane Mangin &lt;<a class="reference external" href="mailto:stephane.mangin&#64;webmel.com">stephane.mangin&#64;webmel.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<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" />
Expand All @@ -483,6 +485,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
Loading