Bug fee cog

This commit is contained in:
2026-05-29 08:07:09 +02:00
parent a9b048d4cf
commit 83f7e43a6e
16 changed files with 768 additions and 8 deletions

View File

@@ -216,9 +216,10 @@ class Fee(ModelSQL,ModelView):
('origin', 'ilike', '%stock.move%'),
])
logger.info("GET_COG_FEE:%s",ml)
if ml:
return round(Decimal(sum([e.credit-e.debit for e in ml if e.description != 'Delivery fee'])),2)
logger.info("GET_COG_FEE:%s",ml)
if ml:
return round(Decimal(sum([e.credit-e.debit for e in ml if e.description != 'Delivery fee'])),2)
return Decimal(0)
def get_non_cog(self,lot):
MoveLine = Pool().get('account.move.line')
@@ -233,9 +234,10 @@ class Fee(ModelSQL,ModelView):
('account', '=', self.product.account_stock_in_used.id),
])
logger.info("GET_NON_COG_FEE:%s",ml)
if ml:
return round(Decimal(sum([e.credit-e.debit for e in ml])),2)
logger.info("GET_NON_COG_FEE:%s",ml)
if ml:
return round(Decimal(sum([e.credit-e.debit for e in ml])),2)
return Decimal(0)
@classmethod
def __setup__(cls):

View File

@@ -1181,6 +1181,46 @@ class PurchaseTradeTestCase(ModuleTestCase):
'fee currency is required for every fee mode'
self.assertTrue(fee_module.Fee.currency.required)
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()
fee.id = 1
fee.product = Mock(account_stock_in_used=Mock(id=2))
lot = Mock(id=3)
move_line = Mock()
move_line.search.return_value = []
with patch('trytond.modules.purchase_trade.fee.Pool') as PoolMock:
PoolMock.return_value.get.side_effect = lambda name: {
'account.move.line': move_line,
'currency.currency': Mock(),
'ir.date': Mock(),
'account.configuration': Mock(return_value=Mock()),
'product.uom': Mock(),
}[name]
self.assertEqual(fee.get_non_cog(lot), Decimal(0))
def test_fee_get_cog_returns_zero_without_move_lines(self):
'fee cog amount is zero before any stock accounting move line exists'
fee = fee_module.Fee()
fee.id = 1
fee.product = Mock(account_stock_in_used=Mock(id=2))
lot = Mock(id=3)
move_line = Mock()
move_line.search.return_value = []
with patch('trytond.modules.purchase_trade.fee.Pool') as PoolMock:
PoolMock.return_value.get.side_effect = lambda name: {
'account.move.line': move_line,
'currency.currency': Mock(),
'ir.date': Mock(),
'account.configuration': Mock(return_value=Mock()),
'product.uom': Mock(),
}[name]
self.assertEqual(fee.get_cog(lot), Decimal(0))
def test_valuation_rejects_fee_without_currency_cleanly(self):
'pnl generation reports a missing fee currency before currency conversion'
fee = Mock(currency=None, product=Mock(name='Maritime freight'))

View File

@@ -73,7 +73,7 @@ this repository contains the full copyright notices and license terms. -->
</page>
<page string="Fees" col="4" id="fees">
<button name="apply_default_fees" icon="tryton-launch"/>
<field name="fees" view_ids="purchase_trade.fee_view_tree_sequence"/>
<field name="fees" colspan="4" view_ids="purchase_trade.fee_view_tree_sequence"/>
</page>
<page string="Mtm" col="4" id="mtm">
<field name="mtm" colspan="4"/>