Fee CN/DN
This commit is contained in:
@@ -13,6 +13,7 @@ from trytond.pyson import Eval
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.exceptions import UserError
|
||||
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
|
||||
from trytond.modules.purchase_trade import lot as lot_module
|
||||
from trytond.modules.purchase_trade import purchase as purchase_module
|
||||
@@ -2607,6 +2608,88 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
save.assert_called_once_with([fee])
|
||||
create_accruals.assert_called_once_with()
|
||||
|
||||
def test_purchase_service_fee_invoice_reverses_previous_line(self):
|
||||
're-invoiced service fee creates a reversal and a current line'
|
||||
Line = base_purchase_module.Line
|
||||
line = Line()
|
||||
line.purchase = Mock(id=20)
|
||||
line.unit_price = Decimal('15')
|
||||
lot = Mock(id=30)
|
||||
invoice_line = Mock(quantity=Decimal('12'), unit_price=Decimal('15'))
|
||||
fee = Mock(
|
||||
state='invoiced',
|
||||
mode='perqt',
|
||||
get_fee_lots_qt=Mock(return_value=Decimal('12')))
|
||||
previous_line = Mock(
|
||||
quantity=Decimal('10'),
|
||||
unit_price=Decimal('11'),
|
||||
invoice=Mock(party=Mock()))
|
||||
reversal_line = Mock()
|
||||
fee_model = Mock()
|
||||
fee_model.search.return_value = [fee]
|
||||
lqt_model = Mock()
|
||||
lqt_model.search.return_value = []
|
||||
invoice_line_model = Mock()
|
||||
invoice_line_model.copy.return_value = [reversal_line]
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase.purchase.Pool'
|
||||
) as PoolMock, patch.object(
|
||||
Line, '_get_last_fee_invoice_line',
|
||||
return_value=previous_line):
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'fee.fee': fee_model,
|
||||
'lot.qt.type': lqt_model,
|
||||
'account.invoice.line': invoice_line_model,
|
||||
}[name]
|
||||
|
||||
result = line._get_service_fee_invoice_lines(invoice_line, lot)
|
||||
|
||||
self.assertEqual(result, [reversal_line, invoice_line])
|
||||
self.assertEqual(invoice_line.fee, fee)
|
||||
self.assertEqual(invoice_line.quantity, Decimal('12'))
|
||||
invoice_line_model.copy.assert_called_once_with(
|
||||
[previous_line], default={
|
||||
'invoice': None,
|
||||
'quantity': Decimal('-10'),
|
||||
'unit_price': Decimal('11'),
|
||||
'party': previous_line.invoice.party,
|
||||
'origin': str(line),
|
||||
})
|
||||
|
||||
def test_purchase_service_fee_invoice_skips_unchanged_reinvoice(self):
|
||||
'unchanged re-invoiced service fee does not create a zero note'
|
||||
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('15'))
|
||||
fee = Mock(
|
||||
state='invoiced',
|
||||
mode='perqt',
|
||||
get_fee_lots_qt=Mock(return_value=Decimal('12')))
|
||||
previous_line = Mock(
|
||||
quantity=Decimal('12'),
|
||||
unit_price=Decimal('15'),
|
||||
invoice=Mock(party=Mock()))
|
||||
fee_model = Mock()
|
||||
fee_model.search.return_value = [fee]
|
||||
lqt_model = Mock()
|
||||
lqt_model.search.return_value = []
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase.purchase.Pool'
|
||||
) as PoolMock, patch.object(
|
||||
Line, '_get_last_fee_invoice_line',
|
||||
return_value=previous_line):
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'fee.fee': fee_model,
|
||||
'lot.qt.type': lqt_model,
|
||||
}[name]
|
||||
|
||||
self.assertEqual(
|
||||
line._get_service_fee_invoice_lines(invoice_line, lot), [])
|
||||
|
||||
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