Skip to content

Commit

Permalink
[FIX] purchase_order_uninvoiced_amount: Allow amount_uninvoiced negative
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralmau authored and pedrobaeza committed Aug 11, 2021
1 parent a96b39e commit e33436b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions purchase_order_uninvoiced_amount/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2020 Tecnativa - Manuel Calero
# Copyright 2020 Tecnativa - Pedro M. Baeza
# Copyright 2020 Tecnativa - João Marques
# Copyright 2021 Tecnativa - Víctor Martínez
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models
from odoo.tools.float_utils import float_compare


class PurchaseOrder(models.Model):
Expand All @@ -28,9 +28,6 @@ def _compute_amount_uninvoiced(self):
qty = line.product_qty - line.qty_invoiced
else:
qty = line.qty_received - line.qty_invoiced
rounding = line.product_uom.rounding
if float_compare(qty, 0.0, precision_rounding=rounding) <= 0:
qty = 0.0
# we use this way for being compatible with purchase_discount
price_unit = (
line.product_qty
Expand Down
1 change: 1 addition & 0 deletions purchase_order_uninvoiced_amount/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* João Marques
* Pedro M. Baeza
* Ernesto Tejeda
* Víctor Martínez
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2020 Tecnativa - Manuel Calero
# Copyright 2020 Tecnativa - Pedro M. Baeza
# Copyright 2021 Tecnativa - Víctor Martínez
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import fields
Expand Down Expand Up @@ -130,3 +131,12 @@ def test_on_ordered_quantities_policy(self):
self.assertEqual(purchase.amount_uninvoiced, 400)
self._create_invoice_from_purchase(purchase)
self.assertEqual(purchase.amount_uninvoiced, 0)

def test_create_purchase_receive_and_invoice_more_qty(self):
purchase = self._create_purchase(10, 10)
self.assertEquals(purchase.amount_uninvoiced, 1000)
invoice = self._create_invoice_from_purchase(purchase)
with Form(invoice) as invoice_form:
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.quantity = 20
self.assertEquals(purchase.amount_uninvoiced, -1000)

0 comments on commit e33436b

Please sign in to comment.