changeset 8c1c6c2198fd in modules/account_payment:default
details: 
https://hg.tryton.org/modules/account_payment?cmd=changeset;node=8c1c6c2198fd
description:
        Merge account kind and account type

        issue4990
        review68401002
diffstat:

 account.py  |  37 +++++++++++++++++++++----------------
 account.xml |   2 +-
 payment.py  |   5 ++++-
 3 files changed, 26 insertions(+), 18 deletions(-)

diffs (103 lines):

diff -r ec397c46968f -r 8c1c6c2198fd account.py
--- a/account.py        Fri Mar 22 15:33:43 2019 +0100
+++ b/account.py        Sun Mar 24 18:00:01 2019 +0100
@@ -47,8 +47,7 @@
         depends=['payment_kind'])
     payment_kind = fields.Function(fields.Selection([
                 (None, ''),
-                ] + KINDS, 'Payment Kind'), 'get_payment_kind',
-        searcher='search_payment_kind')
+                ] + KINDS, 'Payment Kind'), 'get_payment_kind')
     payment_blocked = fields.Boolean('Blocked', readonly=True)
     payment_direct_debit = fields.Boolean("Direct Debit",
         states={
@@ -87,7 +86,8 @@
     def get_payment_amount(cls, lines, name):
         amounts = {}
         for line in lines:
-            if line.account.kind not in ('payable', 'receivable'):
+            if (not line.account.type.payable
+                    and not line.account.type.receivable):
                 amounts[line.id] = None
                 continue
             if line.second_currency:
@@ -107,11 +107,13 @@
         pool = Pool()
         Payment = pool.get('account.payment')
         Account = pool.get('account.account')
+        AccountType = pool.get('account.account.type')
         _, operator, value = clause
         Operator = fields.SQL_OPERATORS[operator]
         table = cls.__table__()
         payment = Payment.__table__()
         account = Account.__table__()
+        account_type = AccountType.__table__()
 
         payment_amount = Sum(Coalesce(payment.amount, 0))
         main_amount = Abs(table.credit - table.debit) - payment_amount
@@ -120,22 +122,25 @@
             else_=second_amount)
         value = cls.payment_amount.sql_format(value)
 
-        query = table.join(payment, type_='LEFT',
-            condition=(table.id == payment.line) & (payment.state != 'failed')
-            ).join(account, condition=table.account == account.id
-                ).select(table.id,
-                    where=account.kind.in_(['payable', 'receivable']),
-                    group_by=(table.id, account.kind, table.second_currency),
-                    having=Operator(amount, value)
-                    )
+        query = (table
+            .join(payment, type_='LEFT',
+            condition=(table.id == payment.line) & (payment.state != 'failed'))
+            .join(account, condition=table.account == account.id)
+            .join(account_type, condition=account.type == account_type.id)
+            .select(table.id,
+                where=(account_type.payable | account_type.receivable),
+                group_by=(table.id, table.second_currency),
+                having=Operator(amount, value)
+                ))
         return [('id', 'in', query)]
 
     def get_payment_kind(self, name):
-        return self.account.kind if self.account.kind in dict(KINDS) else None
-
-    @classmethod
-    def search_payment_kind(cls, name, clause):
-        return [('account.kind',) + tuple(clause[1:])]
+        if (self.account.type.receivable
+                and (self.debit > 0 or self.credit < 0)):
+            return 'receivable'
+        elif (self.account.type.payable
+                and (self.credit > 0 or self.debit < 0)):
+            return 'payable'
 
     @classmethod
     def default_payment_blocked(cls):
diff -r ec397c46968f -r 8c1c6c2198fd account.xml
--- a/account.xml       Fri Mar 22 15:33:43 2019 +0100
+++ b/account.xml       Sun Mar 24 18:00:01 2019 +0100
@@ -27,7 +27,7 @@
             <field name="name">Lines to Pay</field>
             <field name="res_model">account.move.line</field>
             <field name="domain"
-                eval="[('account.kind', 'in', ['receivable', 'payable']), 
('party', '!=', None), ('reconciliation', '=', None), ('payment_amount', '!=', 
0), ('move_state', '=', 'posted')]"
+                eval="[['OR', ('account.type.receivable', '=', True), 
('account.type.payable', '=', True)], ('party', '!=', None), ('reconciliation', 
'=', None), ('payment_amount', '!=', 0), ('move_state', '=', 'posted')]"
                 pyson="1"/>
             <field name="search_value"
                 eval="[('payment_blocked', '=', False)]" pyson="1"/>
diff -r ec397c46968f -r 8c1c6c2198fd payment.py
--- a/payment.py        Fri Mar 22 15:33:43 2019 +0100
+++ b/payment.py        Sun Mar 24 18:00:01 2019 +0100
@@ -146,7 +146,10 @@
                 ['OR', ('debit', '>', 0), ('credit', '<', 0)],
                 ['OR', ('credit', '>', 0), ('debit', '<', 0)],
                 ),
-            ('account.kind', 'in', ['receivable', 'payable']),
+            ['OR',
+                ('account.type.receivable', '=', True),
+                ('account.type.payable', '=', True),
+                ],
             ('party', 'in', [Eval('party', None), None]),
             If(Eval('state') == 'draft',
                 [

Reply via email to