diff --git a/sale.py b/sale.py index a8d0614..06b3d78 100644 --- a/sale.py +++ b/sale.py @@ -2,6 +2,7 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from decimal import Decimal +from sql.operators import And from sql.aggregate import Sum from sql.conditionals import Coalesce @@ -162,13 +163,14 @@ class Sale(metaclass=PoolMeta): condition=(sale.id == payline.sale) ).select( sale.id, - where=((sale.total_amount_cache) & ( + where=(And([ + sale.total_amount_cache != None, sale.state.in_([ 'draft', 'quotation', 'confirmed', 'processing', - 'done']))), + 'done'])])), group_by=(sale.id), having=(Operator( sale.total_amount_cache - Sum(