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
81 changes: 81 additions & 0 deletions purchase_packaging_default/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
==========================
Purchase Packaging Default
==========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f4adb77568893160d1479fbd3bd29a4d4a0b95d247128176778bd0bbbd815844
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_packaging_default
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_packaging_default
: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/purchase-workflow&target_branch=18.0
:alt: Try me on Runboat

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

Allows you to set a default packaging on the order line using the first
packaging defined in the configuration of the respective product Default
packaging quantity is then set based on purchase order line quantity
divided by product packaging quantity. Packaging quantity is rounded up
as we sell it by units. For example: We won't sell 0.5 Boxes or 1.5
Pallets.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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/purchase-workflow/issues/new?body=module:%20purchase_packaging_default%0Aversion:%2018.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
------------

- Telmo Santos <telmo.santos@camptocamp.com>

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/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_packaging_default>`_ 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 purchase_packaging_default/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions purchase_packaging_default/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Purchase Packaging Default",
"version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Purchase Management",
"summary": "Set default packaging in purchase",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"depends": [
"purchase",
],
"data": [
"views/res_config_settings_views.xml",
],
"installable": True,
}
60 changes: 60 additions & 0 deletions purchase_packaging_default/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_packaging_default
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-05-15 09:34+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: purchase_packaging_default
#: model_terms:ir.ui.view,arch_db:purchase_packaging_default.res_config_settings_view_form_purchase
msgid ""
"Assign the first packaging found in product configuration to purchase order"
msgstr ""
"Assegna il primo imballo trovato nella configurazione prodotto all'ordine di "
"acquisto"

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_res_company
msgid "Companies"
msgstr "Aziende"

#. module: purchase_packaging_default
#: model:ir.model.fields,help:purchase_packaging_default.field_res_company__purchase_packaging_default_enabled
#: model:ir.model.fields,help:purchase_packaging_default.field_res_config_settings__purchase_packaging_default_enabled
msgid ""
"In purchase order line get 1st packaging found in product configuration"
msgstr ""
"Nella riga ordine di acquisto prendere il primo imballaggio trovato nella "
"configurazione prodotto"

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_res_config_settings
msgid "Procurement purchase grouping settings"
msgstr "Impostazioni raggruppamento approvvigionamento acquisti"

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_product_packaging
msgid "Product Packaging"
msgstr "Imballaggio prodotto"

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Riga ordine di acquisto"

#. module: purchase_packaging_default
#: model:ir.model.fields,field_description:purchase_packaging_default.field_res_company__purchase_packaging_default_enabled
#: model:ir.model.fields,field_description:purchase_packaging_default.field_res_config_settings__purchase_packaging_default_enabled
msgid "Purchase Packaging Default Enabled"
msgstr "Imballaggio di acquisto predefinito abilitato"
53 changes: 53 additions & 0 deletions purchase_packaging_default/i18n/purchase_packaging_default.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_packaging_default
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \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: purchase_packaging_default
#: model_terms:ir.ui.view,arch_db:purchase_packaging_default.res_config_settings_view_form_purchase
msgid ""
"Assign the first packaging found in product configuration to purchase order"
msgstr ""

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_res_company
msgid "Companies"
msgstr ""

#. module: purchase_packaging_default
#: model:ir.model.fields,help:purchase_packaging_default.field_res_company__purchase_packaging_default_enabled
#: model:ir.model.fields,help:purchase_packaging_default.field_res_config_settings__purchase_packaging_default_enabled
msgid ""
"In purchase order line get 1st packaging found in product configuration"
msgstr ""

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_res_config_settings
msgid "Procurement purchase grouping settings"
msgstr ""

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

#. module: purchase_packaging_default
#: model:ir.model,name:purchase_packaging_default.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: purchase_packaging_default
#: model:ir.model.fields,field_description:purchase_packaging_default.field_res_company__purchase_packaging_default_enabled
#: model:ir.model.fields,field_description:purchase_packaging_default.field_res_config_settings__purchase_packaging_default_enabled
msgid "Purchase Packaging Default Enabled"
msgstr ""
4 changes: 4 additions & 0 deletions purchase_packaging_default/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import purchase_order_line
from . import product_packaging
from . import res_company
from . import res_config_settings
14 changes: 14 additions & 0 deletions purchase_packaging_default/models/product_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2025 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


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

def _find_suitable_product_packaging(self, product_qty, uom_id):
"""Find nothing if you want to keep what was there."""
if self.env.context.get("keep_product_packaging"):
return self.browse()
return super()._find_suitable_product_packaging(product_qty, uom_id)
50 changes: 50 additions & 0 deletions purchase_packaging_default/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2025 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import math

from odoo import api, fields, models


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

def _get_default_packaging(self):
"""From product get 1st packaging found ordered by sequence"""
product_template = self.product_id.product_tmpl_id
return fields.first(product_template.packaging_ids)

@api.onchange("product_id")
def onchange_product_id(self):
res = super().onchange_product_id()
if self.company_id.purchase_packaging_default_enabled:
product_packaging = self._get_default_packaging()
if product_packaging:
self.product_packaging_id = product_packaging
self.product_packaging_qty = 1
return res

@api.depends("product_id", "product_qty", "product_uom")
def _compute_product_packaging_id(self):
_self = self
if self.company_id.purchase_packaging_default_enabled:
_self = _self.with_context(keep_product_packaging=True)
return super(PurchaseOrderLine, _self)._compute_product_packaging_id()

@api.depends("product_packaging_id", "product_uom", "product_qty")
def _compute_product_packaging_qty(self):
res = super()._compute_product_packaging_qty()
for line in self:
if line.product_packaging_qty:
packaging_uom = line.product_packaging_id.product_uom_id
packaging_uom_qty = line.product_uom._compute_quantity(
line.product_qty, packaging_uom
)
# Super computes product_packaging_qty rounding it
# to packaging_uom.precision.
# We must round up that value as we won't sell 0.5,
# 1.6 boxes/pallets.
line.product_packaging_qty = math.ceil(
packaging_uom_qty / line.product_packaging_id.qty
)
return res
13 changes: 13 additions & 0 deletions purchase_packaging_default/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

purchase_packaging_default_enabled = fields.Boolean(
help="In purchase order line get 1st packaging found in product configuration",
)
13 changes: 13 additions & 0 deletions purchase_packaging_default/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

purchase_packaging_default_enabled = fields.Boolean(
related="company_id.purchase_packaging_default_enabled",
readonly=False,
)
3 changes: 3 additions & 0 deletions purchase_packaging_default/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions purchase_packaging_default/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Telmo Santos \<telmo.santos@camptocamp.com\>
6 changes: 6 additions & 0 deletions purchase_packaging_default/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Allows you to set a default packaging on the order line using the first
packaging defined in the configuration of the respective product Default
packaging quantity is then set based on purchase order line quantity
divided by product packaging quantity. Packaging quantity is rounded up
as we sell it by units. For example: We won't sell 0.5 Boxes or 1.5
Pallets.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading