diff --git a/addons/sale/tests/test_sale_to_invoice.py b/addons/sale/tests/test_sale_to_invoice.py index 43a93344ef6..c1d2f261790 100644 --- a/addons/sale/tests/test_sale_to_invoice.py +++ b/addons/sale/tests/test_sale_to_invoice.py @@ -197,6 +197,38 @@ class TestSaleToInvoice(TestSaleCommon): downpayment_line = sale_order.order_line.filtered(lambda l: l.is_downpayment and not l.display_type) self.assertEqual(downpayment_line[0].price_unit, 50, 'The down payment unit price should not change on SO') + def test_downpayment_fixed_amount_with_zero_total_amount(self): + # Create the SO with one line and amount total is zero + sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({ + 'partner_id': self.partner_a.id, + 'partner_invoice_id': self.partner_a.id, + 'partner_shipping_id': self.partner_a.id, + 'pricelist_id': self.company_data['default_pricelist'].id, + 'order_line': [Command.create({ + 'product_id': self.company_data['product_order_no'].id, + 'product_uom_qty': 5, + 'price_unit': 0, + 'tax_id': False, + }), ] + }) + sale_order.action_confirm() + sale_order.order_line.write({'qty_delivered': 5.0}) + context = { + 'active_model': 'sale.order', + 'active_ids': [sale_order.id], + 'active_id': sale_order.id, + 'default_journal_id': self.company_data['default_journal_sale'].id, + } + # Let's do an invoice for a down payment of 50 + downpayment = self.env['sale.advance.payment.inv'].with_context(context).create({ + 'advance_payment_method': 'fixed', + 'fixed_amount': 50, + 'deposit_account_id': self.company_data['default_account_revenue'].id + }) + # Create invoice + downpayment.create_invoices() + self.assertEqual(downpayment.amount, 0.0, 'The down payment amount should be 0.0') + def test_downpayment_percentage_tax_icl(self): """ Test invoice with a percentage downpayment and an included tax Check the total amount of invoice is correct and equal to a respective sale order's total amount diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index ec1801b7162..5730a7b3eec 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -282,7 +282,7 @@ class SaleAdvancePaymentInv(models.TransientModel): if self.advance_payment_method == 'percentage': percentage = self.amount / 100 else: - percentage = self.fixed_amount / order.amount_total + percentage = self.fixed_amount / order.amount_total if order.amount_total else 1 order_lines = order.order_line.filtered(lambda l: not l.display_type) base_downpayment_lines_values = self._prepare_base_downpayment_line_values(order)