-
-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_supplierinfo_packaging
- Loading branch information
Showing
18 changed files
with
885 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
============================== | ||
Product Supplierinfo Packaging | ||
============================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:6369948c1d0331d2737f2d4a2a4fbffc10410bb0c21af4329934eb9fac30706b | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/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--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/16.0/product_supplierinfo_packaging | ||
:alt: OCA/product-attribute | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_supplierinfo_packaging | ||
: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/product-attribute&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module simply allow to select a packaging on a product supplier | ||
info. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
This modules aims to allow linking a packaging to a supplier info in | ||
order to select it automatically on purchase order, and use with | ||
reordering rule. But thoses features are done in separate module. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
- Enable Odoo packaging option | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
1. Go to inventory option and enable packaging | ||
2. Create a packaging for a product | ||
3. Select it on a supplier info, editing packaging quantity will change | ||
supplier info minimum quantity | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_supplierinfo_packaging%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. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* ACSONE SA/NV | ||
|
||
Contributors | ||
------------ | ||
|
||
- Benjamin Willig [email protected] (https://acsone.eu) | ||
|
||
Other credits | ||
------------- | ||
|
||
The development of this module has been financially supported by: | ||
|
||
- ACSONE SA/NV | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_supplierinfo_packaging>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Product Supplierinfo Packaging", | ||
"summary": """ | ||
Allow to specify supplier info quantities using the packaging""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"depends": [ | ||
"product", | ||
], | ||
"data": [ | ||
"views/product_supplierinfo.xml", | ||
], | ||
"demo": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import product_supplierinfo |
148 changes: 148 additions & 0 deletions
148
product_supplierinfo_packaging/models/product_supplierinfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
from odoo.osv.expression import FALSE_DOMAIN | ||
from odoo.tools.float_utils import float_is_zero, float_round | ||
|
||
|
||
class ProductSupplierInfo(models.Model): | ||
_inherit = "product.supplierinfo" | ||
|
||
packaging_id = fields.Many2one( | ||
comodel_name="product.packaging", | ||
ondelete="restrict", | ||
) | ||
packaging_id_domain = fields.Binary(compute="_compute_packaging_id_domain") | ||
packaging_min_qty = fields.Float( | ||
compute="_compute_packaging_min_qty", | ||
inverse="_inverse_packaging_min_qty", | ||
string="Packaging Min. Quantity", | ||
default=0.0, | ||
digits="Product Unit of Measure", | ||
store=True, | ||
readonly=False, | ||
) | ||
packaging_price = fields.Float( | ||
compute="_compute_packaging_price", | ||
inverse="_inverse_packaging_price", | ||
default=0.0, | ||
digits="Product Price", | ||
store=True, | ||
readonly=False, | ||
) | ||
|
||
@api.depends( | ||
"product_id", | ||
"product_tmpl_id", | ||
) | ||
def _compute_packaging_id_domain(self): | ||
for rec in self: | ||
product = rec.product_id | ||
tmpl = rec.product_tmpl_id | ||
domain = [ | ||
("purchase", "=", True), | ||
"|", | ||
("company_id", "=", rec.company_id.id), | ||
("company_id", "=", False), | ||
] | ||
if product: | ||
domain.append(("product_id", "=", product.id)) | ||
elif tmpl: | ||
domain.append( | ||
("product_id.product_tmpl_id", "=", rec.product_tmpl_id.id) | ||
) | ||
else: | ||
domain = FALSE_DOMAIN | ||
rec.packaging_id_domain = domain | ||
|
||
@api.depends("packaging_id", "product_uom", "min_qty") | ||
def _compute_packaging_min_qty(self): | ||
for rec in self: | ||
packaging = rec.packaging_id | ||
packaging_qty = 0.0 | ||
if packaging: | ||
packaging_uom = packaging.product_uom_id | ||
packaging_uom_qty = rec.product_uom._compute_quantity( | ||
rec.min_qty, packaging_uom | ||
) | ||
packaging_qty = float_round( | ||
packaging_uom_qty / packaging.qty, | ||
precision_rounding=packaging_uom.rounding, | ||
) | ||
rec.packaging_min_qty = packaging_qty | ||
|
||
@api.depends( | ||
"price", | ||
"packaging_id", | ||
) | ||
def _compute_packaging_price(self): | ||
price_digits = self.env["decimal.precision"].precision_get("Product Price") | ||
for rec in self: | ||
price = 0 | ||
packaging = rec.packaging_id | ||
if packaging: | ||
price = float_round( | ||
rec.price * packaging.qty, | ||
precision_digits=price_digits, | ||
) | ||
rec.packaging_price = price | ||
|
||
@api.constrains( | ||
"packaging_id", | ||
"product_id", | ||
) | ||
def _check_packaging_id(self): | ||
for rec in self: | ||
packaging = rec.packaging_id | ||
if not packaging: | ||
continue | ||
product = rec.product_id | ||
pack_product = packaging.product_id | ||
tmpl = rec.product_tmpl_id | ||
is_valid = ( | ||
product == packaging.product_id | ||
if product | ||
else pack_product.product_tmpl_id == tmpl | ||
) | ||
if not is_valid: | ||
raise ValidationError( | ||
_( | ||
"Selected packaging (%(packaging)s) is not " | ||
"linked to current product %(product)s", | ||
packaging=rec.display_name, | ||
product=tmpl.display_name, | ||
) | ||
) | ||
|
||
@api.onchange("packaging_min_qty") | ||
def _inverse_packaging_min_qty(self): | ||
for rec in self: | ||
packaging = rec.packaging_id | ||
if not packaging: | ||
continue | ||
packaging_uom = packaging.product_uom_id | ||
uom = rec.product_uom or rec.product_tmpl_id.uom_id | ||
packaging_uom_qty = packaging_uom._compute_quantity( | ||
rec.packaging_min_qty, uom | ||
) | ||
packaging_qty = float_round( | ||
packaging_uom_qty * packaging.qty, | ||
precision_rounding=packaging_uom.rounding, | ||
) | ||
rec.min_qty = packaging_qty | ||
|
||
@api.onchange("packaging_price") | ||
def _inverse_packaging_price(self): | ||
price_digits = self.env["decimal.precision"].precision_get("Product Price") | ||
for rec in self: | ||
packaging = rec.packaging_id | ||
packaging_price = rec.packaging_price | ||
if not packaging or float_is_zero( | ||
packaging_price, precision_digits=price_digits | ||
): | ||
continue | ||
rec.price = float_round( | ||
packaging_price / packaging.qty, precision_digits=price_digits | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To configure this module, you need to: | ||
|
||
- Enable Odoo packaging option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This modules aims to allow linking a packaging to a supplier info in order to select | ||
it automatically on purchase order, and use with reordering rule. But thoses features | ||
are done in separate module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Benjamin Willig <[email protected]> (https://acsone.eu) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The development of this module has been financially supported by: | ||
|
||
- ACSONE SA/NV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module simply allow to select a packaging on a product supplier info. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
To use this module, you need to: | ||
|
||
1. Go to inventory option and enable packaging | ||
2. Create a packaging for a product | ||
3. Select it on a supplier info, editing packaging quantity will change supplier info minimum quantity |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.