diff --git a/purchase_stock_secondary_unit/README.rst b/purchase_stock_secondary_unit/README.rst new file mode 100644 index 00000000000..4ef7deb8584 --- /dev/null +++ b/purchase_stock_secondary_unit/README.rst @@ -0,0 +1,96 @@ +============================= +Purchase Stock Secondary Unit +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2eccf2612961c4c83d2ebf9692d3cc88d112d4f13f57f65111a5aea6180cec62 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_stock_secondary_unit + :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_stock_secondary_unit + :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| + +This module extends the functionality of stock secondary unit module and +purchase_order_secondary_unit to allow copy secondary purchase data to +stock move when a purchase order is confirmed. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module you need to: + +1. Go to a *Product > General Information tab*. +2. Create any record in "Secondary unit of measure". +3. Set the conversion factor. +4. Go to *Purchase > Requests for Quotation* and create a purchase order + with this product. +5. Confirm the purchase order. +6. Go to picking from this purchase order, you will see secondary unit + information. + +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 +------- + +* Jarsa + +Contributors +------------ + +- Alan Ramos + +- `Tecnativa `__: + + - Sergio Teruel + +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_stock_secondary_unit/__init__.py b/purchase_stock_secondary_unit/__init__.py new file mode 100644 index 00000000000..f5738286a8c --- /dev/null +++ b/purchase_stock_secondary_unit/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Jarsa Sistemas +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import models diff --git a/purchase_stock_secondary_unit/__manifest__.py b/purchase_stock_secondary_unit/__manifest__.py new file mode 100644 index 00000000000..5a77aaaa9d5 --- /dev/null +++ b/purchase_stock_secondary_unit/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2020 Jarsa Sistemas +# Copyright 2021 Tecnativa - Sergio Teruel +# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Purchase Stock Secondary Unit", + "summary": "Get product quantities in a secondary unit", + "version": "18.0.1.0.0", + "development_status": "Beta", + "category": "stock", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Jarsa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "purchase_order_secondary_unit", + "stock_secondary_unit", + "purchase_stock", + ], + "auto_install": True, +} diff --git a/purchase_stock_secondary_unit/i18n/de.po b/purchase_stock_secondary_unit/i18n/de.po new file mode 100644 index 00000000000..e524c59fd7e --- /dev/null +++ b/purchase_stock_secondary_unit/i18n/de.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_stock_secondary_unit +#: model:ir.model,name:purchase_stock_secondary_unit.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Bestellposition" + +#~ msgid "Stock Move" +#~ msgstr "Lagerbewegung" diff --git a/purchase_stock_secondary_unit/i18n/es.po b/purchase_stock_secondary_unit/i18n/es.po new file mode 100644 index 00000000000..3209b273a46 --- /dev/null +++ b/purchase_stock_secondary_unit/i18n/es.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-12-25 15:30+0000\n" +"PO-Revision-Date: 2023-07-18 08:10+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\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_stock_secondary_unit +#: model:ir.model,name:purchase_stock_secondary_unit.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Línea de pedido de compra" + +#~ msgid "Stock Move" +#~ msgstr "movimiento de existencias" diff --git a/purchase_stock_secondary_unit/i18n/purchase_stock_secondary_unit.pot b/purchase_stock_secondary_unit/i18n/purchase_stock_secondary_unit.pot new file mode 100644 index 00000000000..3c6d2479ed5 --- /dev/null +++ b/purchase_stock_secondary_unit/i18n/purchase_stock_secondary_unit.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_stock_secondary_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_stock_secondary_unit +#: model:ir.model,name:purchase_stock_secondary_unit.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" diff --git a/purchase_stock_secondary_unit/models/__init__.py b/purchase_stock_secondary_unit/models/__init__.py new file mode 100644 index 00000000000..0358a08d2e5 --- /dev/null +++ b/purchase_stock_secondary_unit/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Jarsa Sistemas +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import purchase_order_line diff --git a/purchase_stock_secondary_unit/models/purchase_order_line.py b/purchase_stock_secondary_unit/models/purchase_order_line.py new file mode 100644 index 00000000000..38d6712cc99 --- /dev/null +++ b/purchase_stock_secondary_unit/models/purchase_order_line.py @@ -0,0 +1,67 @@ +# Copyright 2020 Jarsa Sistemas +# Copyright 2021 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from odoo import api, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _prepare_stock_moves(self, picking): + res = super()._prepare_stock_moves(picking) + # Ensure one method. + # Compute secondary unit values for stock moves. + # When a po line with stock moves has been updated the new moves only + # have the new quantity added so we always want compute the + # secondary unit. + if res: + res[0].update( + { + "secondary_uom_id": self.secondary_uom_id.id, + "secondary_uom_qty": self.secondary_uom_qty, + } + ) + return res + + def write(self, vals): + if "secondary_uom_qty" not in vals: + return super().write(vals) + po_lines = self.filtered( + lambda ln: ln.secondary_uom_qty != vals["secondary_uom_qty"] + ) + res = super().write(vals) + for po_line in po_lines: + moves = po_line.move_ids + if len(moves) == 1: + moves.filtered(lambda sm: sm.state not in ["done", "cancel"]).write( + {"secondary_uom_qty": vals["secondary_uom_qty"]} + ) + elif moves and vals.get("secondary_uom_qty"): + previous_secondary_qty = sum(m.secondary_uom_qty for m in moves[:-1]) + moves[-1:].filtered( + lambda sm: sm.state not in ["done", "cancel"] + ).secondary_uom_qty = vals["secondary_uom_qty"] - previous_secondary_qty + return res + + def _prepare_stock_move_vals( + self, picking, price_unit, product_uom_qty, product_uom + ): + vals = super()._prepare_stock_move_vals( + picking, price_unit, product_uom_qty, product_uom + ) + if self.secondary_uom_id: + vals["secondary_uom_qty"] = self.secondary_uom_qty + vals["secondary_uom_id"] = self.secondary_uom_id.id + return vals + + @api.model + def _prepare_purchase_order_line_from_procurement( + self, product_id, product_qty, product_uom, company_id, values, po + ): + res = super()._prepare_purchase_order_line_from_procurement( + product_id, product_qty, product_uom, company_id, values, po + ) + res["secondary_uom_id"] = values.get("secondary_uom_id", False) + res["secondary_uom_qty"] = values.get("secondary_uom_qty", 0.0) + return res diff --git a/purchase_stock_secondary_unit/pyproject.toml b/purchase_stock_secondary_unit/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_stock_secondary_unit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_stock_secondary_unit/readme/CONTRIBUTORS.md b/purchase_stock_secondary_unit/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..04ae780b3a3 --- /dev/null +++ b/purchase_stock_secondary_unit/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Alan Ramos \ + +- [Tecnativa](https://www.tecnativa.com): + + > - Sergio Teruel \ diff --git a/purchase_stock_secondary_unit/readme/DESCRIPTION.md b/purchase_stock_secondary_unit/readme/DESCRIPTION.md new file mode 100644 index 00000000000..ad5f6a807bd --- /dev/null +++ b/purchase_stock_secondary_unit/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of stock secondary unit module and +purchase_order_secondary_unit to allow copy secondary purchase data to +stock move when a purchase order is confirmed. diff --git a/purchase_stock_secondary_unit/readme/USAGE.md b/purchase_stock_secondary_unit/readme/USAGE.md new file mode 100644 index 00000000000..6d1edace56f --- /dev/null +++ b/purchase_stock_secondary_unit/readme/USAGE.md @@ -0,0 +1,10 @@ +To use this module you need to: + +1. Go to a *Product \> General Information tab*. +2. Create any record in "Secondary unit of measure". +3. Set the conversion factor. +4. Go to *Purchase \> Requests for Quotation* and create a purchase + order with this product. +5. Confirm the purchase order. +6. Go to picking from this purchase order, you will see secondary unit + information. diff --git a/purchase_stock_secondary_unit/static/description/icon.png b/purchase_stock_secondary_unit/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_stock_secondary_unit/static/description/icon.png differ diff --git a/purchase_stock_secondary_unit/static/description/index.html b/purchase_stock_secondary_unit/static/description/index.html new file mode 100644 index 00000000000..1678a9d5209 --- /dev/null +++ b/purchase_stock_secondary_unit/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Purchase Stock Secondary Unit + + + +
+

Purchase Stock Secondary Unit

+ + +

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

+

This module extends the functionality of stock secondary unit module and +purchase_order_secondary_unit to allow copy secondary purchase data to +stock move when a purchase order is confirmed.

+

Table of contents

+ +
+

Usage

+

To use this module you need to:

+
    +
  1. Go to a Product > General Information tab.
  2. +
  3. Create any record in “Secondary unit of measure”.
  4. +
  5. Set the conversion factor.
  6. +
  7. Go to Purchase > Requests for Quotation and create a purchase order +with this product.
  8. +
  9. Confirm the purchase order.
  10. +
  11. Go to picking from this purchase order, you will see secondary unit +information.
  12. +
+
+
+

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

+
    +
  • Jarsa
  • +
+
+
+

Contributors

+ +
+
+

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_stock_secondary_unit/tests/__init__.py b/purchase_stock_secondary_unit/tests/__init__.py new file mode 100644 index 00000000000..6b9fd689ac7 --- /dev/null +++ b/purchase_stock_secondary_unit/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Jarsa Sistemas +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import test_purchase_stock_secondary_unit diff --git a/purchase_stock_secondary_unit/tests/test_purchase_stock_secondary_unit.py b/purchase_stock_secondary_unit/tests/test_purchase_stock_secondary_unit.py new file mode 100644 index 00000000000..2b77de8c888 --- /dev/null +++ b/purchase_stock_secondary_unit/tests/test_purchase_stock_secondary_unit.py @@ -0,0 +1,98 @@ +# Copyright 2020 Jarsa Sistemas +# Copyright 2021 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +import logging + +from odoo.tests import Form +from odoo.addons.base.tests.common import BaseCommon + +_logger = logging.getLogger(__name__) + + +class TestPurchaseStockSecondaryUnit(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Active multiple units of measure security group for user + cls.env.user.groups_id = [(4, cls.env.ref("uom.group_uom").id)] + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.product_uom_kg = cls.env.ref("uom.product_uom_kgm") + cls.product_uom_gram = cls.env.ref("uom.product_uom_gram") + cls.product_uom_unit = cls.env.ref("uom.product_uom_unit") + cls.ProductSecondaryUnit = cls.env["product.secondary.unit"] + cls.partner = cls.env["res.partner"].create({"name": "test - partner"}) + with Form(cls.env["product.product"]) as product_form: + product_form.name = "Test" + with product_form.secondary_uom_ids.new() as secondary_uom: + secondary_uom.name = "box" + secondary_uom.uom_id = cls.product_uom_unit + secondary_uom.factor = 5.0 + cls.product = product_form.save() + cls.secondary_product_uom = cls.product.secondary_uom_ids[:1] + po = cls.env["purchase.order"].new({"partner_id": cls.partner.id}) + po.onchange_partner_id() + cls.purchase_order = cls.env["purchase.order"].create( + po._convert_to_write(po._cache) + ) + with Form(cls.purchase_order) as po_form: + po_form.partner_id = cls.partner + po_form.company_id = cls.env.company + with po_form.order_line.new() as line: + line.product_id = cls.product + line.secondary_uom_id = cls.secondary_product_uom + line.secondary_uom_qty = 2.0 + cls.purchase_order = po_form.save() + + def test_confirm_purchase_order_without_secondary_uom(self): + with Form(self.purchase_order) as po_form: + with po_form.order_line.edit(0) as line: + line.secondary_uom_id = self.ProductSecondaryUnit.browse() + line.secondary_uom_qty = 0.0 + self.purchase_order.button_confirm() + picking = self.purchase_order.picking_ids + self.assertEqual(picking.move_ids.secondary_uom_qty, 0.0) + self.assertFalse(picking.move_ids.secondary_uom_id) + self.assertEqual(picking.move_ids.product_uom_qty, 10.0) + + def test_confirm_new_purchase_order(self): + self.purchase_order.button_confirm() + picking = self.purchase_order.picking_ids + self.assertEqual(picking.move_ids.secondary_uom_qty, 2.0) + self.assertEqual( + picking.move_ids.secondary_uom_id, self.secondary_product_uom + ) + self.assertEqual(picking.move_ids.product_uom_qty, 10.0) + + def test_update_confirmed_purchase_order(self): + self.purchase_order.button_confirm() + with Form(self.purchase_order) as po_form: + with po_form.order_line.edit(0) as line: + line.secondary_uom_qty = 5.0 + picking = self.purchase_order.picking_ids + self.assertEqual(picking.move_ids.secondary_uom_qty, 5.0) + self.assertEqual( + picking.move_ids.secondary_uom_id, self.secondary_product_uom + ) + self.assertEqual(picking.move_ids.product_uom_qty, 25.0) + + def test_update_confirmed_purchase_order_with_move_validated(self): + self.purchase_order.button_confirm() + picking = self.purchase_order.picking_ids + picking.action_assign() + picking.move_line_ids.quantity = picking.move_ids.product_uom_qty + picking.button_validate() + with Form(self.purchase_order) as po_form: + with po_form.order_line.edit(0) as line: + line.secondary_uom_qty = 5.0 + picking = self.purchase_order.picking_ids.filtered(lambda p: p.state != "done") + self.assertEqual(picking.move_ids.secondary_uom_qty, 3.0) + self.assertEqual( + picking.move_ids.secondary_uom_id, self.secondary_product_uom + ) + self.assertEqual(picking.move_ids.product_uom_qty, 15.0) + # Assigned move line + self.assertEqual(picking.move_line_ids.secondary_uom_qty, 3.0) + self.assertEqual( + picking.move_line_ids.secondary_uom_id, self.secondary_product_uom + ) + self.assertEqual(picking.move_line_ids.quantity_product_uom, 15.0)