Get amount

This commit is contained in:
2026-07-21 23:35:39 +02:00
parent ab80f8d909
commit 493dd54606
3 changed files with 32 additions and 13 deletions

View File

@@ -785,6 +785,14 @@ class Fee(ModelSQL,ModelView):
quantity = self.get_quantity()
return Decimal(quantity or 0)
def _get_per_quantity_amount_quantity(self):
quantity = self._get_effective_fee_lots_quantity()
if quantity is None:
quantity = self.quantity
if quantity is None:
quantity = self.get_quantity()
return Decimal(quantity or 0)
@staticmethod
def _unsigned_amount(amount):
if amount is None:
@@ -835,18 +843,9 @@ class Fee(ModelSQL,ModelView):
if self.add_padding:
return self._unsigned_amount(round(
self.get_billing_quantity() * self.price * sign, 2))
if self.shipment_in:
StockMove = Pool().get('stock.move')
sm = StockMove.search(['shipment','=','stock.shipment.in,'+str(self.shipment_in.id)])
if sm:
unique_lots = {e.lot for e in sm if e.lot}
return self._unsigned_amount(round(self.price * Decimal(sum([e.get_current_quantity_converted(0,self.unit) for e in unique_lots])) * sign,2))
LotQt = Pool().get('lot.qt')
lqts = LotQt.search(['lot_shipment_in','=',self.shipment_in.id])
if lqts:
return self._unsigned_amount(round(self.price * Decimal(lqts[0].lot_quantity) * sign,2))
return self._unsigned_amount(round((self.quantity if self.quantity else 0) * self.price * sign,2))
return self._unsigned_amount(round(
self._get_per_quantity_amount_quantity()
* self.price * sign, 2))
elif self.mode == 'pprice':
if self.add_padding:
return self._unsigned_amount(round(

View File

@@ -2700,6 +2700,26 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(fee.quantity, Decimal('40.00000'))
save.assert_called_once_with([fee])
def test_shipment_per_quantity_fee_amount_uses_fee_lots_quantity(self):
'shipment per quantity fee amount ignores unrelated shipment moves'
Fee = Pool().get('fee.fee')
fee = Fee()
fee.mode = 'perqt'
fee.price = Decimal('3.14')
fee.quantity = Decimal('3000')
fee.add_padding = False
fee.shipment_in = Mock(id=7)
with patch.object(
fee, '_get_effective_fee_lots_quantity',
return_value=Decimal('3000')) as lots_quantity, patch(
'trytond.modules.purchase_trade.fee.Pool') as PoolMock:
amount = fee.get_amount()
self.assertEqual(amount, Decimal('9420.00'))
lots_quantity.assert_called_once_with()
PoolMock.assert_not_called()
def test_shipment_fee_lot_domain_keeps_open_virtual_lots(self):
'shipment fee lot domain keeps virtual lots after partial physical add'
Fee = Pool().get('fee.fee')

View File

@@ -33,7 +33,7 @@
<field name="r_operator" width="130" optional="1"/>
<field name="r_bl_date" width="90" optional="1"/>
<field name="r_bl_number" width="110" optional="1"/>
<field name="r_shipping_status" widget="badge" string="Shipping status" badge_colors="shipped:#16a34a,unshipped:#ef4444,planned:#06b6d4,scheduled:#f59e0b,received:#cbd5d5" width="120"/>
<field name="r_shipping_status" widget="badge" string="Shipping status" badge_colors="shipped:#16a34a,unshipped:#ef4444,planned:#06b6d4,scheduled:#f59e0b,received:#64748b" width="120"/>
<field name="r_lot_status"/>
<field name="r_lot_av" width="80" optional="1" tree_invisible="1"/>
<field name="r_purchase_currency_symbol" tree_invisible="1"/>