Skip to content

Commit

Permalink
Merge PR OCA#972 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Sep 7, 2020
2 parents 253e4ff + 531c241 commit 6d444ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions purchase_order_uninvoiced_amount/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2020 Tecnativa - Manuel Calero
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import api, fields, models
Expand All @@ -11,10 +12,14 @@ class PurchaseOrder(models.Model):
def _compute_amount_uninvoiced(self):
for order in self:
amount_uninvoiced = order.amount_untaxed

for line in order.order_line.filtered(lambda x: (x.qty_invoiced != 0)):
amount_uninvoiced -= line.qty_invoiced * line.price_unit

for line in order.order_line.filtered("qty_invoiced"):
# we use this way for being compatible with purchase_discount
price_unit = (
line.product_qty and
line.price_subtotal / line.product_qty or
line.price_unit
)
amount_uninvoiced -= line.qty_invoiced * price_unit
order.update({
'amount_uninvoiced': order.currency_id.round(amount_uninvoiced),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2020 Tecnativa - Manuel Calero
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo.tests.common import SavepointCase
Expand Down Expand Up @@ -105,3 +106,7 @@ def test_create_purchase_create_and_invoiced_with_all_units(self):
self._create_invoice_from_purchase(purchase)
self.assertEquals(purchase.amount_uninvoiced, 0,
"The purchase amount uninvoiced must be 0")

def test_create_purchase_qty_0(self):
purchase = self._create_purchase(0, 0)
self.assertEquals(purchase.amount_uninvoiced, 0)

0 comments on commit 6d444ee

Please sign in to comment.