Fee linked curr
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import datetime
|
||||
from contextlib import nullcontext
|
||||
from decimal import Decimal
|
||||
from unittest.mock import ANY, Mock, patch
|
||||
from xml.etree import ElementTree
|
||||
@@ -2552,6 +2553,59 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertFalse(field.required)
|
||||
self.assertNotIn('required', field.states)
|
||||
|
||||
def test_fee_ensure_ordered_purchase_creates_missing_service_purchase(self):
|
||||
'ordered fee creates missing purchase after linked values are completed'
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee()
|
||||
fee.id = 10
|
||||
fee.type = 'ordered'
|
||||
fee.purchase = None
|
||||
fee.currency = Mock()
|
||||
fee.price = Decimal('12')
|
||||
fee.mode = 'perqt'
|
||||
fee.product = Mock()
|
||||
fee.supplier = Mock(addresses=[])
|
||||
fee.quantity = Decimal('5')
|
||||
fee.unit = Mock()
|
||||
fee.shipment_in = None
|
||||
fee.sale_line = None
|
||||
fee.line = Mock(
|
||||
purchase=Mock(
|
||||
from_location=Mock(),
|
||||
to_location=Mock(),
|
||||
payment_term=Mock()))
|
||||
|
||||
purchase = Mock()
|
||||
purchase_model = Mock(return_value=purchase)
|
||||
line = Mock()
|
||||
line_model = Mock(return_value=line)
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.fee.Pool'
|
||||
) as PoolMock, patch(
|
||||
'trytond.modules.purchase_trade.fee.Transaction'
|
||||
) as TransactionMock, patch.object(
|
||||
Fee, 'save') as save, patch.object(
|
||||
fee, '_get_effective_fee_lots', return_value=[]), patch.object(
|
||||
fee, '_create_fee_accruals') as create_accruals:
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'purchase.purchase': purchase_model,
|
||||
'purchase.line': line_model,
|
||||
}[name]
|
||||
TransactionMock.return_value.set_context.return_value = (
|
||||
nullcontext())
|
||||
|
||||
self.assertTrue(fee.ensure_ordered_purchase())
|
||||
|
||||
self.assertEqual(fee.purchase, purchase)
|
||||
self.assertEqual(purchase.lines, [line])
|
||||
self.assertEqual(purchase.currency, fee.currency)
|
||||
self.assertEqual(line.fee_, fee.id)
|
||||
self.assertEqual(line.unit_price, Decimal('12.0000'))
|
||||
purchase_model.save.assert_called_once_with([purchase])
|
||||
save.assert_called_once_with([fee])
|
||||
create_accruals.assert_called_once_with()
|
||||
|
||||
def test_fee_get_non_cog_returns_zero_without_move_lines(self):
|
||||
'fee non-cog amount is zero before any accounting move line exists'
|
||||
fee = fee_module.Fee()
|
||||
|
||||
Reference in New Issue
Block a user