Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sale_force_invoiced/model/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def _compute_invoice_status(self):
)
return res

@api.depends("force_invoiced")
def _compute_amount_to_invoice(self):
# force_invoiced causes the amount to invoice to be zero
res = super()._compute_amount_to_invoice()
for so in self.filtered("force_invoiced"):
so.amount_to_invoice = 0
return res


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
Expand Down
25 changes: 21 additions & 4 deletions sale_force_invoiced/tests/test_sale_force_invoiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ def _create_product(self, name, product_ctg):
def test_sales_order(self):
so = self.sale_order_model.create({"partner_id": self.customer.id})
sol1 = self.sale_order_line_model.create(
{"product_id": self.service_1.id, "product_uom_qty": 1, "order_id": so.id}
{
"product_id": self.service_1.id,
"product_uom_qty": 1,
"order_id": so.id,
"price_unit": 1.0,
}
)
sol2 = self.sale_order_line_model.create(
{"product_id": self.service_2.id, "product_uom_qty": 2, "order_id": so.id}
{
"product_id": self.service_2.id,
"product_uom_qty": 2,
"order_id": so.id,
"price_unit": 2.0,
}
)

# confirm quotation
so.action_confirm()
# update quantities delivered
Expand Down Expand Up @@ -80,8 +89,16 @@ def test_sales_order(self):
self.assertEqual(
sol2.invoice_status, "invoiced", "The SOL invoice status should be Invoiced"
)

self.assertFalse(
so.amount_to_invoice,
"Amount to invoice when invoice is forced should be 0",
)
so.force_invoiced = False
self.assertEqual(
so.invoice_status, "to invoice", "The invoice status should be To Invoice"
)
self.assertEqual(
so.amount_to_invoice,
sum(so.order_line.mapped("price_total")),
"Amount to invoice when invoice is not forced should be original amount",
)