Add insured amount

This commit is contained in:
2026-04-07 10:54:14 +02:00
parent 2109d7a3e4
commit 5179d98289
4 changed files with 61 additions and 6 deletions

View File

@@ -491,13 +491,32 @@ class ShipmentIn(metaclass=PoolMeta):
total = Decimal('0.0')
currency = None
for move in (self.incoming_moves or []):
quantity = Decimal(str(getattr(move, 'quantity', 0) or 0))
unit_price = Decimal(str(getattr(move, 'unit_price', 0) or 0))
total += (quantity * unit_price)
if not currency:
currency = getattr(move, 'currency', None)
move_amount, move_currency = self._get_report_incoming_move_amount(
move)
total += move_amount
if not currency and move_currency:
currency = move_currency
return total, currency
def _get_report_incoming_move_amount(self, move):
quantity = Decimal(str(getattr(move, 'quantity', 0) or 0))
unit_price = getattr(move, 'unit_price', None)
if unit_price not in (None, ''):
move_currency = getattr(move, 'currency', None)
return quantity * Decimal(str(unit_price or 0)), move_currency
lot = getattr(move, 'lot', None)
line = getattr(lot, 'line', None) if lot else None
if not lot or not line:
return Decimal('0.0'), None
lot_quantity = Decimal(str(
lot.get_current_quantity_converted() or 0))
line_unit_price = Decimal(str(getattr(line, 'unit_price', 0) or 0))
trade = getattr(line, 'purchase', None)
line_currency = getattr(trade, 'currency', None) if trade else None
return lot_quantity * line_unit_price, line_currency
@staticmethod
def _get_report_currency_text(currency):
return (
@@ -574,6 +593,13 @@ class ShipmentIn(metaclass=PoolMeta):
@property
def report_insurance_amount(self):
insured_amount, insured_currency = self._get_report_incoming_amount_data()
if insured_amount:
insured_amount *= Decimal('1.10')
currency_text = self._get_report_currency_text(insured_currency)
amount_text = self._format_report_amount(insured_amount)
return ' '.join(part for part in [currency_text, amount_text] if part)
fee = self._get_report_insurance_fee()
if not fee:
return ''