diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 542888239e2..4297f9cb23d 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -760,6 +760,7 @@ class SaleOrderLine(models.Model): elif not float_is_zero(line.qty_to_invoice, precision_digits=precision): line.invoice_status = 'to invoice' elif line.state == 'sale' and line.product_id.invoice_policy == 'order' and\ + line.product_uom_qty >= 0.0 and\ float_compare(line.qty_delivered, line.product_uom_qty, precision_digits=precision) == 1: line.invoice_status = 'upselling' elif float_compare(line.qty_invoiced, line.product_uom_qty, precision_digits=precision) >= 0: diff --git a/addons/sale/tests/test_sale_order.py b/addons/sale/tests/test_sale_order.py index 497567e8dba..99bb987f9c3 100644 --- a/addons/sale/tests/test_sale_order.py +++ b/addons/sale/tests/test_sale_order.py @@ -108,6 +108,20 @@ class TestSaleOrder(SaleCommon): self.assertEqual(mail_message.author_id, mail_message.partner_ids, 'Sale: author should be in composer recipients thanks to "partner_to" field set on template') self.assertEqual(mail_message.partner_ids, mail_message.sudo().mail_ids.recipient_ids, 'Sale: author should receive mail due to presence in composer recipients') + def test_invoice_state_when_ordered_quantity_is_negative(self): + """When you invoice a SO line with a product that is invoiced on ordered quantities and has negative ordered quantity, + this test ensures that the invoicing status of the SO line is 'invoiced' (and not 'upselling').""" + sale_order = self.env['sale.order'].create({ + 'partner_id': self.partner.id, + 'order_line': [(0, 0, { + 'product_id': self.product.id, + 'product_uom_qty': -1, + })] + }) + sale_order.action_confirm() + sale_order._create_invoices(final=True) + self.assertTrue(sale_order.invoice_status == 'invoiced', 'Sale: The invoicing status of the SO should be "invoiced"') + def test_sale_sequence(self): self.env['ir.sequence'].search([ ('code', '=', 'sale.order'),