Skip to content

Commit

Permalink
[ADD] product_packaging_level_sellable
Browse files Browse the repository at this point in the history
  • Loading branch information
duongtq committed Jul 28, 2023
1 parent a4f0593 commit db5a1ef
Show file tree
Hide file tree
Showing 22 changed files with 949 additions and 0 deletions.
98 changes: 98 additions & 0 deletions product_packaging_level_sellable/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
================================
Product Packaging level sellable
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4ab2dc9342d0521c36acd0af3ea4194581771db03c60432f1a51025404d97c85
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_sellable
: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_sellable
: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|

The creation/update of sale order line will be blocked (by constraints) if the data on the
sale.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 sold: On product packaging type model, this checkbox defines if product
packagings from this particular type are available to be selected on sale
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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product_attribute/issues/new?body=module:%20product_packaging_level_sellable%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

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

* Duong (Tran Quoc) <duongtq@trobz.com>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Camptocamp

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_sellable>`_ 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_sellable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions product_packaging_level_sellable/__manifest__.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)
{
"name": "Product Packaging level sellable",
"summary": "",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product_packaging_level", "sale_stock"],
"data": [
"views/product_packaging.xml",
"views/product_packaging_level.xml",
"views/sale_order_line.xml",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_packaging_level_sellable
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-27 10:31+0000\n"
"PO-Revision-Date: 2023-07-27 10:31+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: product_packaging_level_sellable
#: model:ir.model.fields,field_description:product_packaging_level_sellable.field_product_packaging__can_be_sold
#: model:ir.model.fields,field_description:product_packaging_level_sellable.field_product_packaging_level__can_be_sold
msgid "Can be sold"
msgstr ""

#. module: product_packaging_level_sellable
#: model:ir.model,name:product_packaging_level_sellable.model_product_packaging_level
msgid "Level management for product.packaging"
msgstr ""

#. module: product_packaging_level_sellable
#: model:ir.model.fields,field_description:product_packaging_level_sellable.field_product_packaging_level__packaging_ids
msgid "Packaging"
msgstr ""

#. module: product_packaging_level_sellable
#. odoo-python
#: code:addons/product_packaging_level_sellable/models/sale_order_line.py:0
#, python-format
msgid ""
"Packaging %(packaging)s on product %(product)s must be set as 'Can be sold' "
"in order to be used on a sale order."
msgstr ""

#. module: product_packaging_level_sellable
#: model:ir.model,name:product_packaging_level_sellable.model_product_packaging
msgid "Product Packaging"
msgstr ""

#. module: product_packaging_level_sellable
#: model:ir.model,name:product_packaging_level_sellable.model_sale_order_line
msgid "Sales Order Line"
msgstr ""

#. module: product_packaging_level_sellable
#. odoo-python
#: code:addons/product_packaging_level_sellable/models/sale_order_line.py:0
#, python-format
msgid ""
"This product packaging must be set as 'Can be sold' in order to be used on a"
" sale order."
msgstr ""

#. module: product_packaging_level_sellable
#. odoo-python
#: code:addons/product_packaging_level_sellable/models/sale_order_line.py:0
#, python-format
msgid "Warning"
msgstr ""
3 changes: 3 additions & 0 deletions product_packaging_level_sellable/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 sale_order_line
16 changes: 16 additions & 0 deletions product_packaging_level_sellable/models/product_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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_sold = fields.Boolean(
string="Can be sold", compute="_compute_can_be_sold", readonly=False, store=True
)

@api.depends("packaging_level_id")
def _compute_can_be_sold(self):
for record in self:
record.can_be_sold = record.packaging_level_id.can_be_sold
13 changes: 13 additions & 0 deletions product_packaging_level_sellable/models/product_packaging_level.py
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_sold = fields.Boolean(string="Can be sold", default=True)
packaging_ids = fields.One2many(
comodel_name="product.packaging", inverse_name="packaging_level_id"
)
49 changes: 49 additions & 0 deletions product_packaging_level_sellable/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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 SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _can_be_sold_error_condition(self):
self.ensure_one()
return self.product_packaging_id and not self.product_packaging_id.can_be_sold

@api.constrains("product_packaging_id")
def _check_product_packaging_can_be_sold(self):
for line in self:
if line._can_be_sold_error_condition():
raise ValidationError(
_(
"Packaging %(packaging)s on product %(product)s must be"
" set as 'Can be sold' in order to be used on a sale order."
)
% {
"packaging": line.product_packaging_id.name,
"product": line.product_id.name,
}
)

@api.onchange("product_packaging_id")
def _onchange_product_packaging_id(self):
if self._can_be_sold_error_condition():
return {
"warning": {
"title": _("Warning"),
"message": _(
"This product packaging must be set as 'Can be sold' in"
" order to be used on a sale 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_sold:
line.product_packaging_id = False
return res
5 changes: 5 additions & 0 deletions product_packaging_level_sellable/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module allows odoo users to set:

* Can be sold: On product packaging type model, this checkbox defines if product
packagings from this particular type are available to be selected on sale
order line.
1 change: 1 addition & 0 deletions product_packaging_level_sellable/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Duong (Tran Quoc) <duongtq@trobz.com>
3 changes: 3 additions & 0 deletions product_packaging_level_sellable/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* Camptocamp
2 changes: 2 additions & 0 deletions product_packaging_level_sellable/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The creation/update of sale order line will be blocked (by constraints) if the data on the
sale.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 db5a1ef

Please sign in to comment.