[IMP] sale: handle negative qty with auto invoice
Before this commit, the auto-invoice flow did not consider `sale order` lines with negative quantities. It led to partially paid invoices. Now, invoices generated by the auto-invoice flow are considered final. This will allow `sale order` lines to be invoiced, even with negative quantities. task-2887019 closes odoo/odoo#104277 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -175,7 +175,7 @@ class PaymentTransaction(models.Model):
|
||||
confirmed_orders._force_lines_to_invoice_policy_order()
|
||||
invoices = confirmed_orders.with_context(
|
||||
raise_if_nothing_to_invoice=False
|
||||
)._create_invoices()
|
||||
)._create_invoices(final=True)
|
||||
# Setup access token in advance to avoid serialization failure between
|
||||
# edi postprocessing of invoice and displaying the sale order on the portal
|
||||
for invoice in invoices:
|
||||
|
||||
@@ -259,3 +259,20 @@ class TestSalePayment(AccountPaymentCommon, SaleCommon, PaymentHttpCommon):
|
||||
|
||||
self.assertTrue(tx.invoice_ids)
|
||||
self.assertTrue(self.sale_order.invoice_ids)
|
||||
|
||||
def test_invoice_is_final(self):
|
||||
"""Test that invoice generated from a payment are always final"""
|
||||
# Set automatic invoice
|
||||
self.env['ir.config_parameter'].sudo().set_param('sale.automatic_invoice', 'True')
|
||||
|
||||
# Create the payment
|
||||
self.amount = self.sale_order.amount_total
|
||||
tx = self._create_transaction(
|
||||
flow='redirect', sale_order_ids=[self.sale_order.id], state='done'
|
||||
)
|
||||
with mute_logger('odoo.addons.sale.models.payment_transaction'), patch(
|
||||
'odoo.addons.sale.models.sale_order.SaleOrder._create_invoices'
|
||||
) as _create_invoices_mock:
|
||||
tx._reconcile_after_done()
|
||||
|
||||
self.assertTrue(_create_invoices_mock.call_args.kwargs['final'])
|
||||
|
||||
Reference in New Issue
Block a user