Merge account kind and account type
issue4990 review68401002
This commit is contained in:
1 parent
1c4c1b80ec
commit
e5e8f20313
3 files changed
+26
-18
No files matched your search
+21
-16
@@ -47,8 +47,7 @@ class MoveLine(metaclass=PoolMeta):
|
||||
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 @@ class MoveLine(metaclass=PoolMeta):
|
||||
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 @@ class MoveLine(metaclass=PoolMeta):
|
||||
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 @@ class MoveLine(metaclass=PoolMeta):
|
||||
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):
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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"/>
|
||||
|
||||
+4
-1
@@ -146,7 +146,10 @@ class Payment(Workflow, ModelSQL, ModelView):
|
||||
['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',
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user