From f2707043c46eee5db3d5043983708516cdc9200f Mon Sep 17 00:00:00 2001 From: Alfredo Date: Tue, 15 Oct 2024 12:46:45 +0200 Subject: [PATCH] [14.0][ADD] purchase_line_qty_update_in_picking: When the quantity on the purchase line decreases, update on the picking. --- .../README.rst | 28 +++++++++++++++ .../__init__.py | 1 + .../__manifest__.py | 15 ++++++++ .../models/__init__.py | 1 + .../models/purchase_order_line.py | 34 +++++++++++++++++++ .../purchase_line_qty_update_in_picking | 1 + .../setup.py | 6 ++++ 7 files changed, 86 insertions(+) create mode 100644 purchase_line_qty_update_in_picking/README.rst create mode 100644 purchase_line_qty_update_in_picking/__init__.py create mode 100644 purchase_line_qty_update_in_picking/__manifest__.py create mode 100644 purchase_line_qty_update_in_picking/models/__init__.py create mode 100644 purchase_line_qty_update_in_picking/models/purchase_order_line.py create mode 120000 setup/purchase_line_qty_update_in_picking/odoo/addons/purchase_line_qty_update_in_picking create mode 100644 setup/purchase_line_qty_update_in_picking/setup.py diff --git a/purchase_line_qty_update_in_picking/README.rst b/purchase_line_qty_update_in_picking/README.rst new file mode 100644 index 0000000000..ac80e0adbc --- /dev/null +++ b/purchase_line_qty_update_in_picking/README.rst @@ -0,0 +1,28 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================================== +Purchase line qty update in picking +=================================== + +* When the quantity on the purchase line decreases, update on the picking. + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Alfredo de la Fuente diff --git a/purchase_line_qty_update_in_picking/__init__.py b/purchase_line_qty_update_in_picking/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/purchase_line_qty_update_in_picking/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_line_qty_update_in_picking/__manifest__.py b/purchase_line_qty_update_in_picking/__manifest__.py new file mode 100644 index 0000000000..2840c6eb56 --- /dev/null +++ b/purchase_line_qty_update_in_picking/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Purchase Line Qty Update In Picking", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Avanzosc", + "category": "Inventory", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": [ + "purchase_stock", + ], + "data": [], + "installable": True, +} diff --git a/purchase_line_qty_update_in_picking/models/__init__.py b/purchase_line_qty_update_in_picking/models/__init__.py new file mode 100644 index 0000000000..fa6c0e40fd --- /dev/null +++ b/purchase_line_qty_update_in_picking/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order_line diff --git a/purchase_line_qty_update_in_picking/models/purchase_order_line.py b/purchase_line_qty_update_in_picking/models/purchase_order_line.py new file mode 100644 index 0000000000..b372a4251a --- /dev/null +++ b/purchase_line_qty_update_in_picking/models/purchase_order_line.py @@ -0,0 +1,34 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import _, api, models +from odoo.exceptions import UserError + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + @api.onchange("product_qty", "product_uom", "company_id") + def _onchange_quantity(self): + result = super(PurchaseOrderLine, self)._onchange_quantity() + if self.qty_received and self.product_qty < self.qty_received: + raise UserError(_("Amount less than amount received.")) + return result + + def write(self, values): + found = False + if ( + len(self) == 1 + and "product_qty" in values + and values.get("produt_qty", 0.0) < self.product_qty + ): + found = True + result = super(PurchaseOrderLine, self).write(values) + if found: + self._put_new_qty_in_picking() + return result + + def _put_new_qty_in_picking(self): + qty_in_picking = self.product_qty - self.qty_received + move = self.move_ids.filtered(lambda x: x.state == "assigned") + if len(move) == 1: + move.product_uom_qty = qty_in_picking diff --git a/setup/purchase_line_qty_update_in_picking/odoo/addons/purchase_line_qty_update_in_picking b/setup/purchase_line_qty_update_in_picking/odoo/addons/purchase_line_qty_update_in_picking new file mode 120000 index 0000000000..16470e6d40 --- /dev/null +++ b/setup/purchase_line_qty_update_in_picking/odoo/addons/purchase_line_qty_update_in_picking @@ -0,0 +1 @@ +../../../../purchase_line_qty_update_in_picking \ No newline at end of file diff --git a/setup/purchase_line_qty_update_in_picking/setup.py b/setup/purchase_line_qty_update_in_picking/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_line_qty_update_in_picking/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)