Skip to content

Commit 8fe9304

Browse files
committed
[FIX] sale: create invoice when SO lines are empty
This error occurs when creating an invoice for a sale order with no SO line. Steps to reproduce: - Install 'sale_management' module - Create a New SO and 'Add a Section' > Confirm - Remove SO line > Create Invoice > Down Payment > Create Draft Traceback: TypeError: 'int' object is not iterable At [1], the error occurs because self.order_line.mapped('sequence') returns an empty list. The fallback value 10 is used, but since it's an integer (not a list), it causes a TypeError. [1]- https://github.com/odoo/odoo/blob/f101a9b6d65e34cf3d3175a341b87e3f14c44a02/addons/sale/models/sale_order.py#L2052 sentry-6601545000 closes odoo#210455 X-original-commit: 1436f6e Signed-off-by: Victor Feyens (vfe) <[email protected]> Signed-off-by: Aayush Modi (aamo) <[email protected]>
1 parent 3a3da47 commit 8fe9304

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

addons/sale/models/sale_order.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,7 @@ def _create_down_payment_lines_from_base_lines(self, down_payment_base_lines):
20292029
:return The newly created SO lines.
20302030
"""
20312031
self.ensure_one()
2032-
sequence = max(self.order_line.mapped('sequence') or 10) + 1
2032+
sequence = max(self.order_line.mapped('sequence') or [10]) + 1
20332033
return self.env['sale.order.line'] \
20342034
.with_context(sale_no_log_for_new_lines=True) \
20352035
.create([
@@ -2051,7 +2051,7 @@ def _create_down_payment_section_line_if_needed(self):
20512051
if any(line.display_type and line.is_downpayment for line in self.order_line):
20522052
return
20532053

2054-
sequence = max(self.order_line.mapped('sequence') or 10) + 1
2054+
sequence = max(self.order_line.mapped('sequence') or [10]) + 1
20552055
return self.env['sale.order.line'] \
20562056
.with_context(sale_no_log_for_new_lines=True) \
20572057
.create({

addons/sale/tests/test_sale_to_invoice.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,3 +1330,27 @@ def test_refund_salesteam(self):
13301330
invoice.team_id, team2,
13311331
"Invoice team should be the same as the order's team",
13321332
)
1333+
1334+
def test_invoice_from_order_without_lines(self):
1335+
"""Test that an invoice can be created from a sale order with no product lines"""
1336+
sale_order = self.env['sale.order'].create({'partner_id': self.partner.id})
1337+
self.env['sale.order.line'].create({
1338+
'display_type': 'line_section',
1339+
'name': 'Test section',
1340+
'order_id': sale_order.id,
1341+
}).unlink()
1342+
sale_order.action_confirm()
1343+
wizard = self.env['sale.advance.payment.inv'].with_context({
1344+
'active_model': 'sale.order',
1345+
'active_ids': [sale_order.id],
1346+
'active_id': sale_order.id,
1347+
'default_journal_id': self.company_data['default_journal_sale'].id,
1348+
}).create({
1349+
'advance_payment_method': 'percentage',
1350+
'amount': 10,
1351+
})
1352+
action_values = wizard.create_invoices()
1353+
1354+
invoice = self.env['account.move'].browse(action_values['res_id'])
1355+
self.assertTrue(invoice)
1356+
self.assertEqual(invoice.partner_id, sale_order.partner_id)

0 commit comments

Comments
 (0)