From c80b4ce21b165df93517a50decaedfcc733d4aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Arturo=20Garci=CC=81a?= Date: Wed, 30 Sep 2026 23:44:24 -0400 Subject: [PATCH] Store party NCF defaults per party --- party.py | 14 ++++++++++---- tests/test_sequence_helpers.py | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/party.py b/party.py index 43e8b9e..3fb2e9b 100644 --- a/party.py +++ b/party.py @@ -8,7 +8,7 @@ from sql.conditionals import Coalesce from trytond import backend from trytond.i18n import gettext -from trytond.model import ModelSQL, ValueMixin, fields +from trytond.model import ModelSQL, fields from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.modules.currency.fields import Monetary @@ -40,10 +40,12 @@ supplier_ncf_type = fields.Selection( ) -class Party(metaclass=PoolMeta): +class Party(CompanyMultiValueMixin, metaclass=PoolMeta): __name__ = 'party.party' customer_ncf_type = fields.MultiValue(customer_ncf_type) supplier_ncf_type = fields.MultiValue(supplier_ncf_type) + ncf_types = fields.One2Many( + 'party.party.ncf_type', 'party', "NCF Types") @classmethod def multivalue_model(cls, field): @@ -69,12 +71,16 @@ class Party(metaclass=PoolMeta): 'default_supplier_ncf_type', **pattern) -class PartyNcfType(ModelSQL, ValueMixin): +class PartyNcfType(ModelSQL, CompanyValueMixin): "Party Ncf Type" __name__ = 'party.party.ncf_type' party = fields.Many2One( - 'party.party', "Party", ondelete='CASCADE') + 'party.party', "Party", ondelete='CASCADE', + context={ + 'company': Eval('company', -1), + }, + depends={'company'}) customer_ncf_type = customer_ncf_type supplier_ncf_type = supplier_ncf_type diff --git a/tests/test_sequence_helpers.py b/tests/test_sequence_helpers.py index d99040c..a233ffe 100644 --- a/tests/test_sequence_helpers.py +++ b/tests/test_sequence_helpers.py @@ -8,6 +8,7 @@ from trytond.modules.ncf_manager.sequence import Sequence from trytond.modules.ncf_manager.importer import ( normalize_dgii_row, parse_dgii_authorizations) from trytond.modules.ncf_manager.invoice import Invoice +from trytond.modules.ncf_manager.party import Party, PartyNcfType class NcfManagerUnitTestCase(unittest.TestCase): @@ -73,6 +74,13 @@ class NcfManagerUnitTestCase(unittest.TestCase): self.assertIn('template.type == product_type', source) self.assertIn("line.type == 'line'", source) + def test_party_ncf_type_is_stored_per_party_and_company(self): + self.assertIn('ncf_types', Party._fields) + self.assertEqual( + Party._fields['ncf_types'].model_name, 'party.party.ncf_type') + self.assertIn('party', PartyNcfType._fields) + self.assertIn('company', PartyNcfType._fields) + def test_csv_parser_preserves_unquoted_detail(self): source_format, rows = parse_dgii_authorizations( f'{self.HEADERS}\r\n{self.ROW}\r\n'.encode())