diff --git a/modules/purchase_trade/fee.py b/modules/purchase_trade/fee.py
index c5522ca..5c700f3 100755
--- a/modules/purchase_trade/fee.py
+++ b/modules/purchase_trade/fee.py
@@ -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(
diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py
index 18568e0..47c12b4 100644
--- a/modules/purchase_trade/tests/test_module.py
+++ b/modules/purchase_trade/tests/test_module.py
@@ -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')
diff --git a/modules/purchase_trade/view/lot_report_list.xml b/modules/purchase_trade/view/lot_report_list.xml
index 54651a1..6c39c19 100755
--- a/modules/purchase_trade/view/lot_report_list.xml
+++ b/modules/purchase_trade/view/lot_report_list.xml
@@ -33,7 +33,7 @@
-
+