Skip to content

Commit

Permalink
[14.0][ADD] purchase_line_qty_update_in_picking: When the quantity on…
Browse files Browse the repository at this point in the history
… the purchase line decreases, update on the picking.
  • Loading branch information
alfredoavanzosc authored and anajuaristi committed Feb 3, 2025
1 parent fb98933 commit f270704
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions purchase_line_qty_update_in_picking/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/avanzosc/odoo-addons/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 <[email protected]>
* Alfredo de la Fuente <[email protected]>
1 change: 1 addition & 0 deletions purchase_line_qty_update_in_picking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions purchase_line_qty_update_in_picking/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions purchase_line_qty_update_in_picking/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order_line
34 changes: 34 additions & 0 deletions purchase_line_qty_update_in_picking/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions setup/purchase_line_qty_update_in_picking/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit f270704

Please sign in to comment.