Skip to content

Commit 4a80075

Browse files
committed
[14.0][ADD] sale_pricelist_packaging
1 parent 1256fff commit 4a80075

File tree

15 files changed

+738
-0
lines changed

15 files changed

+738
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
========================
2+
Sale Pricelist Packaging
3+
========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:14e7fa40de1ec46148b3ccae7be7a38dd3d6d213766586d618e604da92091087
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/purchase-workflow/tree/18.0/sale_pricelist_packaging
21+
:alt: OCA/purchase-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-sale_pricelist_packaging
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module adds packaging to the product.pricelist.item and allows you
32+
to sell the same product with different packaging and at different
33+
prices.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Bug Tracker
41+
===========
42+
43+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
44+
In case of trouble, please check there if your issue has already been reported.
45+
If you spotted it first, help us to smash it by providing a detailed and welcomed
46+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20sale_pricelist_packaging%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
47+
48+
Do not contact contributors directly about support or help with technical issues.
49+
50+
Credits
51+
=======
52+
53+
Authors
54+
-------
55+
56+
* Akretion
57+
58+
Contributors
59+
------------
60+
61+
- Mathieu Delva <mathieu.delva@akretion.com>
62+
63+
Maintainers
64+
-----------
65+
66+
This module is maintained by the OCA.
67+
68+
.. image:: https://odoo-community.org/logo.png
69+
:alt: Odoo Community Association
70+
:target: https://odoo-community.org
71+
72+
OCA, or the Odoo Community Association, is a nonprofit organization whose
73+
mission is to support the collaborative development of Odoo features and
74+
promote its widespread use.
75+
76+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/sale_pricelist_packaging>`_ project on GitHub.
77+
78+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Mathieu DELVA <mathieu.delva@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Sale Pricelist Packaging",
7+
"summary": "Sale Pricelist Packaging",
8+
"version": "14.0.1.0.0",
9+
"category": "sale",
10+
"website": "https://github.com/OCA/sale-workflow",
11+
"author": " Akretion, Odoo Community Association (OCA)",
12+
"license": "AGPL-3",
13+
"depends": [
14+
"base",
15+
"sale_stock",
16+
],
17+
"data": ["views/product_pricelist.xml"],
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import product_pricelist
2+
from . import sale_order
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Mathieu DELVA <mathieu.delva@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
from odoo import fields, models
5+
6+
class PricelistItem(models.Model):
7+
_inherit = "product.pricelist.item"
8+
9+
packaging_id = fields.Many2one("product.packaging")
10+
11+
def _is_applicable_for(self, product, qty_in_product_uom):
12+
ctx = self.env.context
13+
print("### _is_applicable_for TRIGGERED", ctx)
14+
if "packaging" in ctx:
15+
if ctx["packaging"] == self.packaging_id:
16+
return super()._is_applicable_for(product, qty_in_product_uom)
17+
return False
18+
19+
elif "packaging" not in ctx and self.packaging_id:
20+
return False
21+
22+
return super()._is_applicable_for(product, qty_in_product_uom)
23+
24+
@classmethod
25+
def _get_applicable_rules(cls, pricer_dict):
26+
"""
27+
Surcharge de _get_applicable_rules pour garantir que les règles avec un packaging_id
28+
soient incluses dans le recordset initial si un packaging est passé dans le contexte.
29+
"""
30+
applicable_rules = super()._get_applicable_rules(pricer_dict)
31+
32+
packaging = cls.env.context.get('packaging')
33+
34+
if packaging:
35+
domain = [
36+
('pricelist_id', 'in', applicable_rules.mapped('pricelist_id').ids),
37+
('product_id', '=', pricer_dict['product'].id),
38+
('packaging_id', '=', packaging.id),
39+
]
40+
41+
42+
packaging_rules = cls.search(domain)
43+
44+
applicable_rules |= packaging_rules
45+
46+
return applicable_rules.sorted(lambda r: (r.sequence, r.id))
47+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Mathieu DELVA <mathieu.delva@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
from odoo import api, models
5+
6+
7+
class SaleOrderLine(models.Model):
8+
_inherit = "sale.order.line"
9+
10+
@api.onchange("product_packaging")
11+
def _onchange_product_packaging(self):
12+
res = super()._onchange_product_packaging()
13+
if self.product_packaging:
14+
self.with_context(packaging=self.product_packaging).product_uom_change()
15+
return res
16+
17+
@api.onchange('product_uom', 'product_uom_qty')
18+
def product_uom_change(self):
19+
if self.product_packaging and "packaging" not in self.env.context:
20+
self = self.with_context(packaging=self.product_packaging)
21+
22+
print("### product_uom_change DÉCLENCHÉ avec le contexte packaging:", self.env.context.get('packaging'))
23+
24+
res = super().product_uom_change()
25+
return res
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Mathieu Delva <mathieu.delva@akretion.com>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module adds packaging to the product.pricelist.item and allows you to sell the same product with different packaging and at different prices.

0 commit comments

Comments
 (0)