changeset d4631b7445d7 in modules/account_payment_braintree:default
details: 
https://hg.tryton.org/modules/account_payment_braintree?cmd=changeset&node=d4631b7445d7
description:
        Add identical party from payments

        issue11385
        review380731002
diffstat:

 __init__.py            |   1 +
 account.py             |  37 +++++++++++++++++++++++++++++++++++++
 party.py               |   7 +++++++
 view/customer_form.xml |   2 ++
 4 files changed, 47 insertions(+), 0 deletions(-)

diffs (106 lines):

diff -r b92a36815954 -r d4631b7445d7 __init__.py
--- a/__init__.py       Mon May 02 17:23:00 2022 +0200
+++ b/__init__.py       Sun Jul 17 19:07:38 2022 +0200
@@ -17,6 +17,7 @@
         account.PaymentBraintreeRefund,
         account.PaymentBraintreeAccount,
         account.PaymentBraintreeCustomer,
+        account.PaymentBraintreeCustomerIdentical,
         account.PaymentBraintreeCustomerPaymentMethodDeleteAsk,
         party.Party,
         party.PartyReceptionDirectDebit,
diff -r b92a36815954 -r d4631b7445d7 account.py
--- a/account.py        Mon May 02 17:23:00 2022 +0200
+++ b/account.py        Sun Jul 17 19:07:38 2022 +0200
@@ -7,6 +7,7 @@
 import braintree
 from braintree.exceptions import GatewayTimeoutError, TooManyRequestsError
 from braintree.exceptions.braintree_error import BraintreeError
+from sql import Literal
 
 from trytond.cache import Cache
 from trytond.config import config
@@ -21,6 +22,7 @@
 from trytond.pool import Pool, PoolMeta
 from trytond.pyson import Bool, Eval
 from trytond.report import Report
+from trytond.tools import sql_pairing
 from trytond.transaction import Transaction
 from trytond.url import http_host
 from trytond.wizard import (
@@ -916,6 +918,13 @@
             'invisible': ~Eval('braintree_error_message'),
             })
 
+    identical_customers = fields.Many2Many(
+        'account.payment.braintree.customer.identical',
+        'source', 'target', "Identical Customers", readonly=True,
+        states={
+            'invisible': ~Eval('identical_customers'),
+            })
+
     _payment_methods_cache = Cache(
         'account_payment_braintree_customer.payment_methods',
         duration=config.getint(
@@ -1146,6 +1155,34 @@
         self._payment_methods_cache.clear()
 
 
+class PaymentBraintreeCustomerIdentical(ModelSQL):
+    "Braintree Customer Identical"
+    __name__ = 'account.payment.braintree.customer.identical'
+    source = fields.Many2One('account.payment.braintree.customer', "Source")
+    target = fields.Many2One('account.payment.braintree.customer', "Target")
+
+    @classmethod
+    def table_query(cls):
+        pool = Pool()
+        Customer = pool.get('account.payment.braintree.customer')
+        source = Customer.__table__()
+        target = Customer.__table__()
+        return (
+            source
+            .join(target, condition=(
+                    source.braintree_customer_id
+                    == target.braintree_customer_id))
+            .select(
+                Literal(0).as_('create_uid'),
+                source.create_date.as_('create_date'),
+                Literal(None).as_('write_uid'),
+                Literal(None).as_('write_date'),
+                sql_pairing(source.id, target.id).as_('id'),
+                source.id.as_('source'),
+                target.id.as_('target'),
+                where=source.id != target.id))
+
+
 class PaymentBraintreeCustomerPaymentMethodDelete(Wizard):
     "Delete Customer Payment Method"
     __name__ = 'account.payment.braintree.customer.payment_method.delete'
diff -r b92a36815954 -r d4631b7445d7 party.py
--- a/party.py  Mon May 02 17:23:00 2022 +0200
+++ b/party.py  Sun Jul 17 19:07:38 2022 +0200
@@ -13,6 +13,13 @@
     braintree_customers = fields.One2Many(
         'account.payment.braintree.customer', 'party', "Braintree Customers")
 
+    def _payment_identical_parties(self):
+        parties = super()._payment_identical_parties()
+        for customer in self.braintree_customers:
+            for other_customer in customer.identical_customers:
+                parties.add(other_customer.party)
+        return parties
+
     @classmethod
     def write(cls, *args):
         pool = Pool()
diff -r b92a36815954 -r d4631b7445d7 view/customer_form.xml
--- a/view/customer_form.xml    Mon May 02 17:23:00 2022 +0200
+++ b/view/customer_form.xml    Sun Jul 17 19:07:38 2022 +0200
@@ -21,4 +21,6 @@
 
     <label name="braintree_error_message"/>
     <field name="braintree_error_message" colspan="3" yexpand="0" height="80"/>
+
+    <field name="identical_customers" colspan="4"/>
 </form>

Reply via email to