From f75d52a8b119f0c77f4d6eff5a47f473364bf155 Mon Sep 17 00:00:00 2001 From: Sergio Morillo Date: Wed, 21 Nov 2018 13:10:57 +0100 Subject: [PATCH] Fix multivalue implementation. This commit refs #6311 --- party.py | 8 ++++++++ tests/test_account_invoice.py | 25 ++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/party.py b/party.py index 13e0e98..9e735eb 100644 --- a/party.py +++ b/party.py @@ -30,6 +30,14 @@ class Party: return pool.get('party.party.invoice_to') return super(Party, cls).multivalue_model(field) + def multivalue_record(self, field, **pattern): + Value = self.multivalue_model(field) + if Value.__name__ == 'party.party.invoice_to': + pattern = pattern.copy() + pattern['party'] = self + return Value(**pattern) + return super(Party, self).multivalue_record(field, **pattern) + class PartyInvoiceTo(ModelSQL, CompanyValueMixin): "Party Invoice to" diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index 8b060c1..e5ed93c 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -1,16 +1,35 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. import unittest +from trytond.pool import Pool import trytond.tests.test_tryton -from trytond.tests.test_tryton import ModuleTestCase +from trytond.tests.test_tryton import ModuleTestCase, with_transaction class TestCase(ModuleTestCase): """Test module""" module = 'account_invoice_party_invoice_to' - def setUp(self): - super(TestCase, self).setUp() + @with_transaction() + def test_party(self): + 'Test configuration accounts are used as fallback on party' + pool = Pool() + Party = pool.get('party.party') + + party1 = Party(name='Party to pay') + party1.save() + self.assertIsNone(party1.customer_to_invoice) + self.assertIsNone(party1.supplier_to_invoice) + + party2 = Party(name='Party to receive') + party2.save() + + party = Party(name='Party') + party.customer_to_invoice = party1 + party.supplier_to_invoice = party2 + party.save() + self.assertEqual(party.customer_to_invoice, party1) + self.assertEqual(party.supplier_to_invoice, party2) def suite():