This commit is contained in:
2026-07-15 07:58:02 +02:00
parent cf0c0923a6
commit 9b0dd0e7c1
3 changed files with 73 additions and 15 deletions

View File

@@ -1697,7 +1697,42 @@ class ShipmentIn(metaclass=PoolMeta):
+ self._get_report_linkage_sale_lines()):
for fee in getattr(line, 'fees', []) or []:
add_fee(fee)
return fees
return [
fee for fee in fees
if self._report_linkage_fee_applies_to_report_lots(fee)]
def _get_report_linkage_fee_lots(self, fee):
get_lots = getattr(fee, '_get_effective_fee_lots', None)
if callable(get_lots):
lots = get_lots()
if lots:
return list(lots)
lots = getattr(fee, 'lots', None)
if lots:
return list(lots)
return []
def _report_linkage_fee_applies_to_report_lots(self, fee):
report_lots = self._get_report_linkage_lots()
if not report_lots:
return True
fee_lots = self._get_report_linkage_fee_lots(fee)
if fee_lots:
report_lot_keys = {
self._report_record_key(lot) for lot in report_lots}
return any(
self._report_record_key(lot) in report_lot_keys
for lot in fee_lots)
trade_line = self._get_report_linkage_fee_trade_line(fee)
report_lines = (
self._get_report_linkage_purchase_lines()
+ self._get_report_linkage_sale_lines())
report_line_keys = {
self._report_record_key(line) for line in report_lines}
return (
not trade_line
or self._report_record_key(trade_line) in report_line_keys)
def _get_report_linkage_fee_trade_line(self, fee):
return (
@@ -1727,9 +1762,10 @@ class ShipmentIn(metaclass=PoolMeta):
or self._get_report_linkage_sale())
for fee in self._get_report_linkage_fees():
trade_line = self._get_report_linkage_fee_trade_line(fee)
trade = self._get_report_linkage_fee_trade(fee) or fallback_trade
key = (
self._report_record_key(trade),
self._report_record_key(trade_line or trade),
self._report_record_key(getattr(fee, 'product', None)),
self._report_record_key(getattr(fee, 'supplier', None)),
)
@@ -1755,7 +1791,7 @@ class ShipmentIn(metaclass=PoolMeta):
(self._report_fee_amount(fee) for fee in budgeted),
Decimal('0'))
validated = estimated
if self._report_linkage_is_final and ordered:
if ordered:
validated = sum(
(self._report_fee_amount(fee) for fee in ordered),
Decimal('0'))
@@ -1768,10 +1804,6 @@ class ShipmentIn(metaclass=PoolMeta):
})
return pairs
@property
def _report_linkage_is_final(self):
return getattr(self, 'report_linkage_status', None) == 'FINAL'
@classmethod
def _report_fee_amount(cls, fee):
get_amount = getattr(fee, 'get_amount', None)
@@ -1810,8 +1842,10 @@ class ShipmentIn(metaclass=PoolMeta):
rows.append((
'Purchases', '', purchase_total, purchase_total,
'major'))
rows.append(('', '', '', '', 'spacer'))
if sale_lines:
rows.append(('Sales', '', sale_total, sale_total, 'major'))
rows.append(('', '', '', '', 'spacer'))
fee_estimated_total = Decimal('0')
fee_validated_total = Decimal('0')
@@ -1836,6 +1870,7 @@ class ShipmentIn(metaclass=PoolMeta):
rows.append((
'Costs', 'Total', fee_estimated_total,
fee_validated_total, 'cost'))
rows.append(('', '', '', '', 'spacer'))
estimated_pnl = purchase_total + sale_total + fee_estimated_total
validated_pnl = purchase_total + sale_total + fee_validated_total
rows.append(('P&L', '', estimated_pnl, validated_pnl, 'pnl'))
@@ -4659,14 +4694,18 @@ class LotReportLinkageRecord:
+ self._get_report_linkage_sale_lines()):
for fee in getattr(line, 'fees', []) or []:
add_fee(fee)
return fees
return [
fee for fee in fees
if self._report_linkage_fee_applies_to_report_lots(fee)]
_get_report_linkage_fee_lots = ShipmentIn._get_report_linkage_fee_lots
_report_linkage_fee_applies_to_report_lots = (
ShipmentIn._report_linkage_fee_applies_to_report_lots)
_get_report_linkage_fee_trade_line = (
ShipmentIn._get_report_linkage_fee_trade_line)
_get_report_linkage_fee_trade = ShipmentIn._get_report_linkage_fee_trade
_get_report_linkage_fee_pairs = ShipmentIn._get_report_linkage_fee_pairs
_report_linkage_fee_type = ShipmentIn._report_linkage_fee_type
_report_linkage_is_final = ShipmentIn._report_linkage_is_final
_get_report_linkage_summary_rows = (
ShipmentIn._get_report_linkage_summary_rows)

View File

@@ -6990,19 +6990,38 @@ description</t></is></c>
quantity=Decimal('1'),
mode='lumpsum',
p_r='pay')
purchase_line.fees = [budgeted_fee, ordered_fee]
other_ordered_fee = SimpleNamespace(
id=203,
type='ordered',
line=purchase_line,
sale_line=None,
product=fee_product,
supplier=supplier,
price=Decimal('999'),
quantity=Decimal('1'),
mode='lumpsum',
p_r='pay')
purchase_line.fees = [budgeted_fee, ordered_fee, other_ordered_fee]
lot = SimpleNamespace(
id=101,
lot_type='physic',
line=purchase_line,
sale_line=None)
other_lot = SimpleNamespace(
id=102,
lot_type='physic',
line=purchase_line,
sale_line=None)
budgeted_fee.lots = [lot]
ordered_fee.lots = [lot]
other_ordered_fee.lots = [other_lot]
shipment.incoming_moves = [SimpleNamespace(lot=lot)]
provisional_fee_row = [
row for row in shipment._get_report_linkage_summary_rows()
if row[0] == 'Costs' and row[1] == 'Maritime freight'][0]
self.assertEqual(provisional_fee_row[2], Decimal('-100'))
self.assertEqual(provisional_fee_row[3], Decimal('-100'))
self.assertEqual(provisional_fee_row[3], Decimal('-125'))
shipment.report_linkage_status = 'FINAL'
final_fee_row = [

View File

@@ -363,7 +363,7 @@
<style:table-row-properties style:min-row-height="0.011cm"/>
</style:style>
<style:style style:name="LKFinancialSummary.7" style:family="table-row">
<style:table-row-properties style:min-row-height="0.11cm"/>
<style:table-row-properties style:min-row-height="0.191cm"/>
</style:style>
<style:style style:name="LKSection_5f_3" style:display-name="LKSection_3" style:family="table">
<style:table-properties style:width="28.6cm" table:align="margins"/>
@@ -1110,7 +1110,7 @@
<style:text-properties style:font-name="Arial" fo:font-size="11pt"/>
</style:style>
<style:style style:name="P85" style:family="paragraph" style:parent-style-name="Standard">
<style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" style:contextual-spacing="false" fo:line-height="100%"/>
<style:paragraph-properties fo:margin-top="0.03cm" fo:margin-bottom="0cm" style:contextual-spacing="false" fo:line-height="100%"/>
<style:text-properties style:font-name="Arial" fo:font-size="11pt" fo:font-weight="bold"/>
</style:style>
<style:style style:name="P86" style:family="paragraph" style:parent-style-name="Standard">
@@ -1186,11 +1186,11 @@
<style:text-properties style:font-name="Arial" fo:font-size="8pt" fo:font-weight="bold"/>
</style:style>
<style:style style:name="P105" style:family="paragraph" style:parent-style-name="Standard">
<style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" style:contextual-spacing="false" fo:line-height="72%"/>
<style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" style:contextual-spacing="false" fo:line-height="90%"/>
<style:text-properties style:font-name="Arial" fo:font-size="7pt"/>
</style:style>
<style:style style:name="P106" style:family="paragraph" style:parent-style-name="Standard">
<style:paragraph-properties fo:line-height="72%" fo:text-align="end" style:justify-single-word="false"/>
<style:paragraph-properties fo:line-height="90%" fo:text-align="end" style:justify-single-word="false"/>
<style:text-properties style:font-name="Arial" fo:font-size="7pt"/>
</style:style>
<style:style style:name="P107" style:family="paragraph" style:parent-style-name="Standard">