From 2bcbf169cf90c14dfbf8fc43fbb3b8af5302d568 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Tue, 4 Aug 2026 22:24:59 +0200 Subject: [PATCH] GL bug --- modules/account/account.py | 20 +++++++++++++++++++- modules/account/tests/test_module.py | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/account/account.py b/modules/account/account.py index 12a45f3..453c63b 100755 --- a/modules/account/account.py +++ b/modules/account/account.py @@ -3080,8 +3080,26 @@ class GeneralLedgerDetail(DescriptionOriginMixin, ModelSQL, ModelView): payments = Payment.search([('line', '=', self.move_line.id)], limit=1) return payments[0] if payments else None + @staticmethod + def _resolve_reference(value): + if not value or hasattr(value, '__name__'): + return value + if not isinstance(value, str): + return None + try: + model_name, record_id = value.split(',', 1) + record_id = int(record_id) + except ValueError: + return None + try: + Model = Pool().get(model_name) + except KeyError: + return None + return Model(record_id) + def get_document_field(self, name): - origin = self.move.origin if self.move else None + origin = self._resolve_reference( + self.origin or (self.move.origin if self.move else None)) if origin: model_name = origin.__name__ if model_name == 'account.invoice': diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index ef785f0..3f5808b 100755 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -2196,5 +2196,22 @@ class AccountTestCase( 'to_date': datetime.date(2026, 1, 31), }) + @with_transaction() + def test_general_ledger_detail_document_field_reference_string(self): + "Test General Ledger Detail document fields resolve reference strings" + pool = Pool() + Detail = pool.get('account.general_ledger.detail') + Party = pool.get('party.party') + + party = Party(name='Customer') + party.save() + + detail = Detail() + detail.origin = '%s,%s' % (Party.__name__, party.id) + + self.assertIsNone(detail.get_document_field('document_number')) + self.assertEqual(detail.get_document_field('document_type'), + party.rec_name) + del ModuleTestCase