|
|
"""
Compute the invoice status of a SO line. Possible statuses:
- no: if the SO is not in status 'sale', we consider that there is nothing to
invoice. This is also the default value if the conditions of no other status is met.
- to invoice: we refer to the quantity to invoice of the line. Refer to method
`_compute_qty_to_invoice()` for more information on how this quantity is calculated.
- upselling: this is possible only for a product invoiced on ordered quantities for which
we delivered more than expected. The could arise if, for example, a project took more
time than expected but we decided not to invoice the extra cost to the client. This
occurs only in state 'sale', the upselling opportunity is removed from the list.
- invoiced: the quantity invoiced is larger or equal to the quantity ordered.
"""
precision = self.env["decimal.precision"].precision_get("Product Unit")
for line in self:
if line.state != "sale":
line.invoice_status = "no"
elif line.is_downpayment and line.untaxed_amount_to_invoice == 0:
line.invoice_status = "invoiced"
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
and not (line.qty_overage and line.order_id.invoice_overages)
):
line.invoice_status = "upselling"
elif (
float_compare(line.qty_invoiced, line.product_uom_qty, precision_digits=precision)
>= 0
):
line.invoice_status = "invoiced"
else:
line.invoice_status = "no"
|
|