Skip to content

Commit

Permalink
[ADD] product_packaging_level_purchasable
Browse files Browse the repository at this point in the history
  • Loading branch information
santostelmo committed Oct 25, 2023
1 parent bda6cf0 commit 9d25850
Show file tree
Hide file tree
Showing 18 changed files with 824 additions and 0 deletions.
88 changes: 88 additions & 0 deletions product_packaging_level_purchasable/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
===================================
Product Packaging level purchasable
===================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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_packaging_level_purchasable
: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_packaging_level_purchasable
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

The creation/update of purchase order line will be blocked (by constraints) if the data on the
purchase.order.line does not fit with the configuration of the product's packagings.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

This module allows odoo users to set:

* Can be purchased: On a product packaging level as default value for a new product packaging. On a product packaging to make it available or not on a purchase order line.

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_packaging_level_purchasable%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
~~~~~~~

* Camptocamp
* BCIM

Contributors
~~~~~~~~~~~~

* Telmo Santos <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[email protected]>

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_packaging_level_purchasable>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_packaging_level_purchasable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions product_packaging_level_purchasable/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Product Packaging level purchasable",
"summary": "",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "Camptocamp, BCIM, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product_packaging_level", "purchase_stock"],
"data": [
"views/product_packaging_level.xml",
],
}
3 changes: 3 additions & 0 deletions product_packaging_level_purchasable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_packaging
from . import product_packaging_level
from . import purchase_order_line
20 changes: 20 additions & 0 deletions product_packaging_level_purchasable/models/product_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import api, fields, models


class ProductPackaging(models.Model):
_inherit = "product.packaging"

can_be_purchased = fields.Boolean(
compute="_compute_can_be_purchased",
readonly=False,
store=True,
help="If true, the packaging can be used for purchase orders",
)

@api.depends("packaging_level_id")
def _compute_can_be_purchased(self):
for record in self:
record.can_be_purchased = record.packaging_level_id.can_be_purchased
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductPackagingLevel(models.Model):
_inherit = "product.packaging.level"

can_be_purchased = fields.Boolean(string="Can be purchased", default=True)
packaging_ids = fields.One2many(
comodel_name="product.packaging", inverse_name="packaging_level_id"
)
58 changes: 58 additions & 0 deletions product_packaging_level_purchasable/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import _, api, models
from odoo.exceptions import ValidationError


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

def _can_be_purchased_error_condition(self):
self.ensure_one()
return (
self.product_packaging_id and not self.product_packaging_id.can_be_purchased
)

@api.constrains("product_packaging_id")
def _check_product_packaging_can_be_purchased(self):
errors = []
for line in self:
if line._can_be_purchased_error_condition():
errors.append(
_(
"Packaging %(packaging)s on product %(product)s must be"
" set as 'Can be purchased' in order to be used on a purchase order."
)
% {
"packaging": line.product_packaging_id.name,
"product": line.product_id.name,
}
)
if errors:
raise ValidationError("\n".join(errors))

@api.onchange("product_packaging_id")
def _onchange_product_packaging_id(self):
if self._can_be_purchased_error_condition():
return {
"warning": {
"title": _("Warning"),
"message": _(
"This product packaging must be set as 'Can be purchased' in"
" order to be used on a purchase order."
),
},
}
return super()._onchange_product_packaging_id()

@api.depends("product_id", "product_uom_qty", "product_uom")
def _compute_product_packaging_id(self):
res = super()._compute_product_packaging_id()
for line in self:
if (
line.product_packaging_id
and not line.product_packaging_id.can_be_purchased
):
line.product_packaging_id = False
return res
3 changes: 3 additions & 0 deletions product_packaging_level_purchasable/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows odoo users to set:

* Can be purchased: On a product packaging level as default value for a new product packaging. On a product packaging to make it available or not on a purchase order line.
2 changes: 2 additions & 0 deletions product_packaging_level_purchasable/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Telmo Santos <[email protected]>
* Jacques-Etienne Baudoux (BCIM) <[email protected]>
2 changes: 2 additions & 0 deletions product_packaging_level_purchasable/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The creation/update of purchase order line will be blocked (by constraints) if the data on the
purchase.order.line does not fit with the configuration of the product's packagings.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9d25850

Please sign in to comment.