details:   https://code.tryton.org/tryton/commit/caee544d2261
branch:    default
user:      Cédric Krier <[email protected]>
date:      Sun Sep 14 12:23:08 2025 +0200
description:
        Add party's address to the SEPA mandate

        Use explicit address selection to display on the SEPA mandate instead 
of the
        default first address.

        Closes #14229
diffstat:

 doc/migration.rst                                                    |  20 
+++++++
 modules/account_payment_sepa/CHANGELOG                               |   1 +
 modules/account_payment_sepa/mandate.fodt                            |  18 
+++---
 modules/account_payment_sepa/payment.py                              |  28 
++++++++-
 modules/account_payment_sepa/tests/scenario_account_payment_sepa.rst |   6 ++
 modules/account_payment_sepa/tests/test_module.py                    |   1 +
 modules/account_payment_sepa/view/mandate_form.xml                   |   5 +
 modules/account_payment_sepa/view/mandate_list.xml                   |   1 +
 8 files changed, 67 insertions(+), 13 deletions(-)

diffs (227 lines):

diff -r 00d4a20bf151 -r caee544d2261 doc/migration.rst
--- a/doc/migration.rst Sat Sep 13 11:22:40 2025 +0200
+++ b/doc/migration.rst Sun Sep 14 12:23:08 2025 +0200
@@ -14,6 +14,26 @@
 .. warning::
    You cannot skip more than 2 series ending with ``.0``.
 
+7.8
+---
+
+After
+~~~~~
+
+* If ``account_payment_sepa`` module is activated, fill the address of
+  validated mandates with default value with the ``trytond-console``:
+
+  .. code-block:: python
+
+     Mandate = pool.get('account.payment.sepa.mandate')
+     mandates = Mandate.search([
+         ('state', '=', 'validated'),
+         ('address', '=', None),
+         ])
+     for mandate in mandates:
+         mandate.address = mandate.on_change_party()
+     Mandate.save(mandates)
+
 7.6
 ---
 
diff -r 00d4a20bf151 -r caee544d2261 modules/account_payment_sepa/CHANGELOG
--- a/modules/account_payment_sepa/CHANGELOG    Sat Sep 13 11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/CHANGELOG    Sun Sep 14 12:23:08 2025 +0200
@@ -1,3 +1,4 @@
+* Add party's address to the mandate
 
 Version 7.6.0 - 2025-04-28
 --------------------------
diff -r 00d4a20bf151 -r caee544d2261 modules/account_payment_sepa/mandate.fodt
--- a/modules/account_payment_sepa/mandate.fodt Sat Sep 13 11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/mandate.fodt Sun Sep 14 12:23:08 2025 +0200
@@ -753,7 +753,7 @@
       <text:p text:style-name="P16">Your address</text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" 
table:number-columns-spanned="2" office:value-type="string">
-      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.party.addresses[0].street if 
mandate.party.addresses else &apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.address.street if mandate.address else 
&apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:covered-table-cell/>
     </table:table-row>
@@ -771,10 +771,10 @@
       <text:p text:style-name="P15"/>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B5" office:value-type="string">
-      <text:p text:style-name="Table_20_Contents"><text:placeholder 
text:placeholder-type="text">&lt;mandate.party.addresses[0].postal_code if 
mandate.party.addresses else &apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="Table_20_Contents"><text:placeholder 
text:placeholder-type="text">&lt;mandate.address.postal_code if mandate.address 
else &apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" office:value-type="string">
-      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.party.addresses[0].city if 
mandate.party.addresses else &apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.address.city if mandate.address else 
&apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
     </table:table-row>
     <table:table-row>
@@ -793,7 +793,7 @@
       <text:p text:style-name="P21"/>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" 
table:number-columns-spanned="2" office:value-type="string">
-      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.party.addresses[0].country.rec_name if 
mandate.party.addresses and mandate.party.addresses[0].country else 
&apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P13"><text:placeholder 
text:placeholder-type="text">&lt;mandate.address.country.rec_name if 
mandate.address and mandate.address.country else 
&apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:covered-table-cell/>
     </table:table-row>
@@ -883,7 +883,7 @@
       <text:p text:style-name="P15"/>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" 
table:number-columns-spanned="2" office:value-type="string">
-      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company.party.addresses[0].street if 
mandate.company.party.addresses else 
&apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company_address.street if 
mandate.company_address else &apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:covered-table-cell/>
     </table:table-row>
@@ -901,10 +901,10 @@
       <text:p text:style-name="P15"/>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B5" office:value-type="string">
-      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company.party.addresses[0].postal_code 
if mandate.company.party.addresses else 
&apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company_address.postal_code if 
mandate.company_address else &apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" office:value-type="string">
-      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company.party.addresses[0].city if 
mandate.company.party.addresses else 
&apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company_address.city if 
mandate.company_address else &apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
     </table:table-row>
     <table:table-row>
@@ -923,7 +923,7 @@
       <text:p text:style-name="P15"/>
      </table:table-cell>
      <table:table-cell table:style-name="Table1.B1" 
table:number-columns-spanned="2" office:value-type="string">
-      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company.party.addresses[0].country.rec_name
 if mandate.company.party.addresses and 
mandate.company.party.addresses[0].country else 
&apos;&apos;&gt;</text:placeholder></text:p>
+      <text:p text:style-name="P14"><text:placeholder 
text:placeholder-type="text">&lt;mandate.company_address.country.rec_name if 
mandate.company_address and mandate.company_address.country else 
&apos;&apos;&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:covered-table-cell/>
     </table:table-row>
@@ -1018,4 +1018,4 @@
    <text:p text:style-name="P31"><text:placeholder 
text:placeholder-type="text">&lt;/for&gt;</text:placeholder></text:p>
   </office:text>
  </office:body>
-</office:document>
\ No newline at end of file
+</office:document>
diff -r 00d4a20bf151 -r caee544d2261 modules/account_payment_sepa/payment.py
--- a/modules/account_payment_sepa/payment.py   Sat Sep 13 11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/payment.py   Sun Sep 14 12:23:08 2025 +0200
@@ -26,7 +26,8 @@
 from trytond.pyson import Eval, If
 from trytond.report import Report
 from trytond.tools import (
-    grouped_slice, is_full_text, lstrip_wildcard, reduce_ids, sortable_values)
+    cached_property, grouped_slice, is_full_text, lstrip_wildcard, reduce_ids,
+    sortable_values)
 from trytond.transaction import Transaction
 
 from .sepa_handler import CAMT054
@@ -503,12 +504,19 @@
             'company': Eval('company', -1),
             },
         depends={'company'})
+    address = fields.Many2One(
+        'party.address', "Address",
+        domain=[
+            ('party', '=', Eval('party', -1)),
+            ],
+        states={
+            'readonly': Eval('state').in_(['validated', 'cancelled']),
+            'required': Eval('state') == 'validated',
+            })
     account_number = fields.Many2One('bank.account.number', 'Account Number',
         ondelete='RESTRICT',
         states={
-            'readonly': (
-                Eval('state').in_(['validated', 'cancelled'])
-                | ~Eval('party')),
+            'readonly': Eval('state').in_(['validated', 'cancelled']),
             'required': Eval('state') == 'validated',
             },
         domain=[
@@ -603,6 +611,14 @@
                 t, (t.state, Index.Equality(cardinality='low')),
                 where=t.state.in_(['draft', 'requested'])))
 
+    @fields.depends('party', '_parent_party.id')
+    def on_change_party(self):
+        if self.party and self.party.id >= 0:
+            self.address = self.party.address_get()
+        else:
+            self.address = None
+            self.account_number = None
+
     @staticmethod
     def default_company():
         return Transaction().context.get('company')
@@ -612,6 +628,10 @@
         self.identification_readonly = self.default_identification_readonly(
             company=self.company.id if self.company else None)
 
+    @cached_property
+    def company_address(self):
+        return self.company.party.address_get()
+
     @staticmethod
     def default_type():
         return 'recurrent'
diff -r 00d4a20bf151 -r caee544d2261 
modules/account_payment_sepa/tests/scenario_account_payment_sepa.rst
--- a/modules/account_payment_sepa/tests/scenario_account_payment_sepa.rst      
Sat Sep 13 11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/tests/scenario_account_payment_sepa.rst      
Sun Sep 14 12:23:08 2025 +0200
@@ -82,6 +82,12 @@
     >>> mandate.identification = 'MANDATE'
     >>> mandate.type = 'recurrent'
     >>> mandate.click('request')
+    >>> mandate.state
+    'requested'
+
+    >>> mandate_report = Report('account.payment.sepa.mandate')
+    >>> _ = mandate_report.execute([mandate])
+
     >>> mandate.signature_date = today
     >>> mandate.click('validate_mandate')
     >>> mandate.state
diff -r 00d4a20bf151 -r caee544d2261 
modules/account_payment_sepa/tests/test_module.py
--- a/modules/account_payment_sepa/tests/test_module.py Sat Sep 13 11:22:40 
2025 +0200
+++ b/modules/account_payment_sepa/tests/test_module.py Sun Sep 14 12:23:08 
2025 +0200
@@ -74,6 +74,7 @@
     return Mandate.create([{
                 'company': company,
                 'party': customer,
+                'address': customer.addresses[0],
                 'account_number': account.numbers[0],
                 'identification': 'MANDATE',
                 'type': 'recurrent',
diff -r 00d4a20bf151 -r caee544d2261 
modules/account_payment_sepa/view/mandate_form.xml
--- a/modules/account_payment_sepa/view/mandate_form.xml        Sat Sep 13 
11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/view/mandate_form.xml        Sun Sep 14 
12:23:08 2025 +0200
@@ -4,8 +4,13 @@
 <form>
     <label name="party"/>
     <field name="party"/>
+    <label name="address"/>
+    <field name="address"/>
+
     <label name="account_number"/>
     <field name="account_number"/>
+    <newline/>
+
     <label name="company"/>
     <field name="company"/>
     <newline/>
diff -r 00d4a20bf151 -r caee544d2261 
modules/account_payment_sepa/view/mandate_list.xml
--- a/modules/account_payment_sepa/view/mandate_list.xml        Sat Sep 13 
11:22:40 2025 +0200
+++ b/modules/account_payment_sepa/view/mandate_list.xml        Sun Sep 14 
12:23:08 2025 +0200
@@ -4,6 +4,7 @@
 <tree>
     <field name="company" expand="1" optional="1"/>
     <field name="party" expand="2"/>
+    <field name="address" expand="1" optional="1"/>
     <field name="account_number" expand="1"/>
     <field name="identification" expand="1"/>
     <field name="type"/>

Reply via email to