changeset 6ee0054a3cd5 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset&node=6ee0054a3cd5
description:
        Avoid NULL value for cost and revenue

        It is needed to avoid NULL value because CategoryTree.get_total sum 
them.

        issue10389
        review344131002
diffstat:

 stock_reporting_margin.py |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (34 lines):

diff -r 3670b1a582ec -r 6ee0054a3cd5 stock_reporting_margin.py
--- a/stock_reporting_margin.py Sat May 15 09:20:43 2021 +0200
+++ b/stock_reporting_margin.py Sun May 16 17:43:33 2021 +0200
@@ -5,7 +5,7 @@
 
 from sql import Null, Literal, With
 from sql.aggregate import Sum, Min, Max
-from sql.conditionals import Case
+from sql.conditionals import Case, Coalesce
 from sql.functions import CurrentTimestamp, DateTrunc, Power, Ceil, Log, Round
 
 try:
@@ -157,7 +157,8 @@
     def _column_cost(cls, tables, withs, sign):
         move = tables['move']
         return Sum(
-            sign * cls.cost.sql_cast(move.internal_quantity) * move.cost_price)
+            sign * cls.cost.sql_cast(move.internal_quantity)
+            * Coalesce(move.cost_price, 0))
 
     @classmethod
     def _column_revenue(cls, tables, withs, sign):
@@ -165,8 +166,9 @@
         currency = withs['currency_rate']
         currency_company = withs['currency_rate_company']
         return Sum(
-            sign * cls.revenue.sql_cast(move.quantity) * move.unit_price
-            * currency_company.rate / currency.rate)
+            sign * cls.revenue.sql_cast(move.quantity)
+            * Coalesce(move.unit_price, 0)
+            * Coalesce(currency_company.rate / currency.rate, 0))
 
     @classmethod
     def _group_by(cls, tables, withs):

Reply via email to