From a1bb0e8a04283bf363e1db833191327a8b166901 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Tue, 28 Jul 2026 07:35:59 +0200 Subject: [PATCH] Show insurance surveyor address --- .../docs/template-properties.md | 7 +-- modules/purchase_trade/stock.py | 50 ++++++++++++++++++- modules/purchase_trade/tests/test_module.py | 19 +++++++ modules/stock/insurance.fodt | 2 +- 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/modules/purchase_trade/docs/template-properties.md b/modules/purchase_trade/docs/template-properties.md index 826bdde..0d8512e 100644 --- a/modules/purchase_trade/docs/template-properties.md +++ b/modules/purchase_trade/docs/template-properties.md @@ -417,9 +417,10 @@ Usage typique: (`lot.line.unit_price * lot.get_current_quantity_converted()`) - `report_insurance_amount_insured`: `110%` de `report_insurance_incoming_amount` -- `report_insurance_contact_surveyor`: surveyor affiche sous - `Contact the following surveyor` (priorite au champ shipment `surveyor`, - puis fallback controller / fee `Insurance`) +- `report_insurance_contact_surveyor`: nom et adresse du surveyor affiches + sous `Contact the following surveyor` (priorite au champ shipment + `surveyor`, puis fallback controller / fee `Insurance`). La premiere ligne + d'adresse est ignoree si elle duplique le nom long de la party. - base de travail pour un certificat d'assurance lie a un shipment ## 10) Recommandations diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index c3c1a64..a4fec24 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -1319,9 +1319,57 @@ class ShipmentIn(metaclass=PoolMeta): supplier = getattr(fee, 'supplier', None) if fee else None return getattr(supplier, 'rec_name', '') or '' + def _get_report_insurance_surveyor_party(self): + if self.surveyor: + return self.surveyor + if self.controller: + return self.controller + fee = self._get_report_insurance_fee() + return getattr(fee, 'supplier', None) if fee else None + + @staticmethod + def _normalize_report_address_line(value): + return ' '.join(str(value or '').split()).strip().casefold() + + @classmethod + def _get_report_party_address_lines(cls, party): + if not party: + return [] + name = getattr(party, 'rec_name', '') or '' + lines = [name] if name else [] + address_get = getattr(party, 'address_get', None) + address = address_get() if address_get else None + if not address: + return lines + + duplicate_names = { + cls._normalize_report_address_line(value) + for value in [ + name, + getattr(party, 'full_name', None), + getattr(address, 'party_name', None), + getattr(address, 'party_full_name', None), + ] + if value + } + full_address = getattr(address, 'full_address', '') or '' + if not isinstance(full_address, str): + return lines + address_lines = [ + line.strip() + for line in full_address.splitlines() + if line.strip() + ] + for line in address_lines: + if cls._normalize_report_address_line(line) in duplicate_names: + continue + lines.append(line) + return lines + @property def report_insurance_contact_surveyor(self): - return self.report_insurance_surveyor + party = self._get_report_insurance_surveyor_party() + return '\n'.join(self._get_report_party_address_lines(party)) @property def report_insurance_issue_place_and_date(self): diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 9234d51..722b4d5 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -7765,6 +7765,25 @@ description self.assertEqual( shipment.report_insurance_surveyor, 'SGS') + def test_shipment_insurance_contact_surveyor_includes_address_once(self): + 'insurance contact surveyor displays name and address without duplicate party name' + ShipmentIn = Pool().get('stock.shipment.in') + shipment = ShipmentIn() + address = Mock( + party_name='SGS SA', + party_full_name='SGS SA', + full_address='SGS SA\nRue du Test 1\n1201 Geneva\nSwitzerland') + shipment.surveyor = Mock( + rec_name='SGS', + full_name='SGS SA', + address_get=Mock(return_value=address)) + shipment.controller = Mock(rec_name='CONTROL UNION') + shipment.fees = [] + + self.assertEqual( + shipment.report_insurance_contact_surveyor, + 'SGS\nRue du Test 1\n1201 Geneva\nSwitzerland') + def test_shipment_insurance_order_reference_falls_back_to_lot_qt(self): 'insurance order reference can read sale deal through matching lot.qt' ShipmentIn = Pool().get('stock.shipment.in') diff --git a/modules/stock/insurance.fodt b/modules/stock/insurance.fodt index 73ecf52..90fdeb8 100644 --- a/modules/stock/insurance.fodt +++ b/modules/stock/insurance.fodt @@ -1053,7 +1053,7 @@ applicable) and strike as per hte according Clauses. In case of loss and/or damage, contact the following surveyor: - <records[0].report_insurance_contact_surveyor or ''> + <for each="line in (records[0].report_insurance_contact_surveyor or '').splitlines()"><line></for> Surveyor's functions are limited to that of an independent observer retained for the sole purpose of reporting on the nature extent and proximate cause of loss; the surveyor has no authority to represent underwriters with regard to the terms and conditions of the contract.