29.03.26
This commit is contained in:
2
modules/purchase_trade/tests/__init__.py
Normal file
2
modules/purchase_trade/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
52
modules/purchase_trade/tests/test_module.py
Normal file
52
modules/purchase_trade/tests/test_module.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from decimal import Decimal
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class PurchaseTradeTestCase(ModuleTestCase):
|
||||
'Test purchase_trade module'
|
||||
module = 'purchase_trade'
|
||||
|
||||
@with_transaction()
|
||||
def test_get_totals_without_rows(self):
|
||||
'get_totals returns zeros when the query has no row'
|
||||
Valuation = Pool().get('valuation.valuation')
|
||||
cursor = Mock()
|
||||
cursor.fetchone.return_value = None
|
||||
connection = Mock()
|
||||
connection.cursor.return_value = cursor
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.valuation.Transaction'
|
||||
) as Transaction, patch.object(
|
||||
Valuation, '__table__', return_value='valuation_valuation'):
|
||||
Transaction.return_value.connection = connection
|
||||
|
||||
self.assertEqual(
|
||||
Valuation.get_totals(), (Decimal(0), Decimal(0)))
|
||||
|
||||
@with_transaction()
|
||||
def test_get_totals_without_previous_total(self):
|
||||
'get_totals converts null variation to zero'
|
||||
Valuation = Pool().get('valuation.valuation')
|
||||
cursor = Mock()
|
||||
cursor.fetchone.return_value = (Decimal('42.50'), None)
|
||||
connection = Mock()
|
||||
connection.cursor.return_value = cursor
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.valuation.Transaction'
|
||||
) as Transaction, patch.object(
|
||||
Valuation, '__table__', return_value='valuation_valuation'):
|
||||
Transaction.return_value.connection = connection
|
||||
|
||||
self.assertEqual(
|
||||
Valuation.get_totals(), (Decimal('42.50'), Decimal(0)))
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -459,9 +459,13 @@ class Valuation(ValuationBase, ModelView):
|
||||
"""
|
||||
|
||||
cursor.execute(sql)
|
||||
last_total, last_variation = cursor.fetchone()
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
return Decimal(0), Decimal(0)
|
||||
|
||||
return last_total, last_variation
|
||||
last_total, last_variation = row
|
||||
|
||||
return last_total or Decimal(0), last_variation or Decimal(0)
|
||||
|
||||
class ValuationLine(ValuationBase, ModelView):
|
||||
"Last Valuation"
|
||||
|
||||
Reference in New Issue
Block a user