CN/DN commission
This commit is contained in:
@@ -11,7 +11,7 @@ from xml.etree import ElementTree
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.exceptions import UserError, UserWarning
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.purchase import purchase as base_purchase_module
|
||||
from trytond.modules.purchase_trade import valuation as valuation_module
|
||||
@@ -2690,6 +2690,118 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(
|
||||
line._get_service_fee_invoice_lines(invoice_line, lot), [])
|
||||
|
||||
def test_purchase_service_percent_price_fee_invoice_uses_amount_line(self):
|
||||
'% price service fee invoice uses a single amount line'
|
||||
Line = base_purchase_module.Line
|
||||
line = Line()
|
||||
line.purchase = Mock(id=20)
|
||||
lot = Mock(id=30)
|
||||
invoice_line = Mock(quantity=Decimal('12'), unit_price=Decimal('50'))
|
||||
fee = Mock(
|
||||
state='not invoiced',
|
||||
mode='pprice',
|
||||
warn_percent_price_partial_lots=Mock())
|
||||
fee_model = Mock()
|
||||
fee_model.search.return_value = [fee]
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase.purchase.Pool'
|
||||
) as PoolMock:
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'fee.fee': fee_model,
|
||||
}[name]
|
||||
|
||||
result = line._get_service_fee_invoice_lines(invoice_line, lot)
|
||||
|
||||
self.assertEqual(result, [invoice_line])
|
||||
self.assertEqual(invoice_line.fee, fee)
|
||||
self.assertEqual(invoice_line.quantity, 1)
|
||||
self.assertEqual(invoice_line.unit_price, Decimal('50'))
|
||||
fee.warn_percent_price_partial_lots.assert_called_once_with()
|
||||
|
||||
def test_percent_price_fee_amount_uses_full_line_amount(self):
|
||||
'% price fee ignores quantity when all line lots are linked'
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee()
|
||||
lot = SimpleNamespace(id=1, lot_type='physic')
|
||||
fee.mode = 'pprice'
|
||||
fee.price = Decimal('2')
|
||||
fee.quantity = Decimal('999')
|
||||
fee.sale_line = None
|
||||
fee.shipment_in = None
|
||||
fee.line = SimpleNamespace(
|
||||
amount=Decimal('1000'),
|
||||
unit_price=Decimal('10'),
|
||||
lots=[lot])
|
||||
|
||||
with patch.object(
|
||||
fee, '_get_effective_fee_lots', return_value=[lot]):
|
||||
self.assertEqual(fee.get_amount(), Decimal('20.00'))
|
||||
|
||||
def test_percent_price_fee_warns_when_line_lots_are_partial(self):
|
||||
'% price fee warns when it does not cover all line lots'
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee()
|
||||
lot_1 = SimpleNamespace(id=1, lot_type='physic')
|
||||
lot_2 = SimpleNamespace(id=2, lot_type='physic')
|
||||
fee.mode = 'pprice'
|
||||
fee.line = SimpleNamespace(lots=[lot_1, lot_2])
|
||||
fee.sale_line = None
|
||||
warning = Mock()
|
||||
warning.format.return_value = 'partial-pprice-fee'
|
||||
warning.check.return_value = True
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.fee.Pool'
|
||||
) as PoolMock, patch.object(
|
||||
fee, '_get_effective_fee_lots', return_value=[lot_1]):
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'res.user.warning': warning,
|
||||
}[name]
|
||||
|
||||
with self.assertRaises(UserWarning):
|
||||
fee.warn_percent_price_partial_lots()
|
||||
|
||||
warning.format.assert_called_once_with(
|
||||
"Partial % price fee lots", [fee])
|
||||
warning.check.assert_called_once_with('partial-pprice-fee')
|
||||
|
||||
def test_percent_price_fee_adjusts_purchase_to_amount_line(self):
|
||||
'% price fee keeps generated purchase as one amount line'
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee()
|
||||
fee.type = 'ordered'
|
||||
fee.mode = 'pprice'
|
||||
fee.amount = Decimal('20')
|
||||
fee.product = Mock()
|
||||
fee.supplier = Mock()
|
||||
fee.currency = Mock()
|
||||
purchase_line = Mock(
|
||||
unit_price=Decimal('10'),
|
||||
quantity=Decimal('999'),
|
||||
product=fee.product)
|
||||
fee.purchase = Mock(
|
||||
lines=[purchase_line],
|
||||
party=fee.supplier,
|
||||
currency=fee.currency)
|
||||
purchase_model = Mock()
|
||||
purchase_line_model = Mock()
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.fee.Pool'
|
||||
) as PoolMock:
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'purchase.purchase': purchase_model,
|
||||
'purchase.line': purchase_line_model,
|
||||
}[name]
|
||||
|
||||
fee.adjust_purchase_values()
|
||||
|
||||
self.assertEqual(purchase_line.unit_price, Decimal('20'))
|
||||
self.assertEqual(purchase_line.quantity, 1)
|
||||
purchase_line_model.save.assert_called_once_with([purchase_line])
|
||||
purchase_model.save.assert_called_once_with([fee.purchase])
|
||||
|
||||
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