diff --git a/purchase_packaging_default/README.rst b/purchase_packaging_default/README.rst new file mode 100644 index 00000000000..f181ad49e55 --- /dev/null +++ b/purchase_packaging_default/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Telmo Santos + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_packaging_default/__init__.py b/purchase_packaging_default/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_packaging_default/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_packaging_default/__manifest__.py b/purchase_packaging_default/__manifest__.py new file mode 100644 index 00000000000..91b2f386013 --- /dev/null +++ b/purchase_packaging_default/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp (). +# 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, +} diff --git a/purchase_packaging_default/i18n/it.po b/purchase_packaging_default/i18n/it.po new file mode 100644 index 00000000000..9a6433d3de2 --- /dev/null +++ b/purchase_packaging_default/i18n/it.po @@ -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 \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" diff --git a/purchase_packaging_default/i18n/purchase_packaging_default.pot b/purchase_packaging_default/i18n/purchase_packaging_default.pot new file mode 100644 index 00000000000..a7497de2e1e --- /dev/null +++ b/purchase_packaging_default/i18n/purchase_packaging_default.pot @@ -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 "" diff --git a/purchase_packaging_default/models/__init__.py b/purchase_packaging_default/models/__init__.py new file mode 100644 index 00000000000..c25a446120d --- /dev/null +++ b/purchase_packaging_default/models/__init__.py @@ -0,0 +1,4 @@ +from . import purchase_order_line +from . import product_packaging +from . import res_company +from . import res_config_settings diff --git a/purchase_packaging_default/models/product_packaging.py b/purchase_packaging_default/models/product_packaging.py new file mode 100644 index 00000000000..a59a5442847 --- /dev/null +++ b/purchase_packaging_default/models/product_packaging.py @@ -0,0 +1,14 @@ +# Copyright 2025 Camptocamp (). +# 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) diff --git a/purchase_packaging_default/models/purchase_order_line.py b/purchase_packaging_default/models/purchase_order_line.py new file mode 100644 index 00000000000..5e7325707fd --- /dev/null +++ b/purchase_packaging_default/models/purchase_order_line.py @@ -0,0 +1,50 @@ +# Copyright 2025 Camptocamp (). +# 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 diff --git a/purchase_packaging_default/models/res_company.py b/purchase_packaging_default/models/res_company.py new file mode 100644 index 00000000000..b710377a9d9 --- /dev/null +++ b/purchase_packaging_default/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2025 Camptocamp (). +# 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", + ) diff --git a/purchase_packaging_default/models/res_config_settings.py b/purchase_packaging_default/models/res_config_settings.py new file mode 100644 index 00000000000..256453eb815 --- /dev/null +++ b/purchase_packaging_default/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2025 Camptocamp (). +# 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, + ) diff --git a/purchase_packaging_default/pyproject.toml b/purchase_packaging_default/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_packaging_default/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_packaging_default/readme/CONTRIBUTORS.md b/purchase_packaging_default/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..08b9f3e73d4 --- /dev/null +++ b/purchase_packaging_default/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Telmo Santos \ diff --git a/purchase_packaging_default/readme/DESCRIPTION.md b/purchase_packaging_default/readme/DESCRIPTION.md new file mode 100644 index 00000000000..dd993d72b23 --- /dev/null +++ b/purchase_packaging_default/readme/DESCRIPTION.md @@ -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. diff --git a/purchase_packaging_default/static/description/icon.png b/purchase_packaging_default/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_packaging_default/static/description/icon.png differ diff --git a/purchase_packaging_default/static/description/index.html b/purchase_packaging_default/static/description/index.html new file mode 100644 index 00000000000..b35ba20b8d8 --- /dev/null +++ b/purchase_packaging_default/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Purchase Packaging Default + + + +
+

Purchase Packaging Default

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_packaging_default/tests/__init__.py b/purchase_packaging_default/tests/__init__.py new file mode 100644 index 00000000000..e9bc0933dd6 --- /dev/null +++ b/purchase_packaging_default/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_packaging_default diff --git a/purchase_packaging_default/tests/test_purchase_packaging_default.py b/purchase_packaging_default/tests/test_purchase_packaging_default.py new file mode 100644 index 00000000000..27d6f8f6590 --- /dev/null +++ b/purchase_packaging_default/tests/test_purchase_packaging_default.py @@ -0,0 +1,41 @@ +# Copyright 2025 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests import Form + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT +from odoo.addons.product.tests.common import ProductCommon + + +class PurchasePackagingDefault(ProductCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.user.groups_id |= cls.env.ref("product.group_stock_packaging") + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + cls.config = cls.env["res.config.settings"].create({}) + cls.config.purchase_packaging_default_enabled = True + cls.config.set_values() + with Form(cls.product) as product_f: + with product_f.packaging_ids.new() as packaging_f: + packaging_f.name = "Pallet" + packaging_f.qty = 240 + packaging_f.purchase = True + with product_f.packaging_ids.new() as packaging_f: + packaging_f.name = "Big Box" + packaging_f.qty = 24 + packaging_f.purchase = True + cls.pallet, cls.big_box = cls.product.packaging_ids + + def test_purchase_packaging_default(self): + po_f = Form(self.env["purchase.order"]) + po_f.partner_id = self.partner + with po_f.order_line.new() as line_f: + line_f.product_id = self.product + line_f.product_qty = 120 + # We take the first available packaging + self.assertEqual(line_f.product_packaging_id, self.pallet) + # Packaging qty is round up to 1 + self.assertEqual(line_f.product_packaging_qty, 1) + # Packaging qty is round up to 2 + line_f.product_qty = 241 + self.assertEqual(line_f.product_packaging_qty, 2) diff --git a/purchase_packaging_default/views/res_config_settings_views.xml b/purchase_packaging_default/views/res_config_settings_views.xml new file mode 100644 index 00000000000..24bbba8af81 --- /dev/null +++ b/purchase_packaging_default/views/res_config_settings_views.xml @@ -0,0 +1,30 @@ + + + + res.config.settings.view.form.inherit.purchase + res.config.settings + + + + +
+
+ +
+
+
+
+
+
+
+