Allow to block payment of line
issue5889 review30511002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Allow to block payment of line
|
||||
* Ask payment journal for each currency
|
||||
* Decrease amount to pay of invoice
|
||||
* Add group Payment Approval
|
||||
|
||||
+45
@@ -44,6 +44,7 @@ class MoveLine:
|
||||
(None, ''),
|
||||
] + KINDS, 'Payment Kind'), 'get_payment_kind',
|
||||
searcher='search_payment_kind')
|
||||
payment_blocked = fields.Boolean('Blocked', readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
@@ -52,7 +53,14 @@ class MoveLine:
|
||||
'pay': {
|
||||
'invisible': ~Eval('payment_kind').in_(dict(KINDS).keys()),
|
||||
},
|
||||
'payment_block': {
|
||||
'invisible': Eval('payment_blocked', False),
|
||||
},
|
||||
'payment_unblock': {
|
||||
'invisible': ~Eval('payment_blocked', False),
|
||||
},
|
||||
})
|
||||
cls._check_modify_exclude.add('payment_blocked')
|
||||
|
||||
@classmethod
|
||||
def get_payment_amount(cls, lines, name):
|
||||
@@ -108,6 +116,10 @@ class MoveLine:
|
||||
def search_payment_kind(cls, name, clause):
|
||||
return [('account.kind',) + tuple(clause[1:])]
|
||||
|
||||
@classmethod
|
||||
def default_payment_blocked(cls):
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def copy(cls, lines, default=None):
|
||||
if default is None:
|
||||
@@ -122,6 +134,27 @@ class MoveLine:
|
||||
def pay(cls, lines):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def payment_block(cls, lines):
|
||||
pool = Pool()
|
||||
Payment = pool.get('account.payment')
|
||||
|
||||
cls.write(lines, {
|
||||
'payment_blocked': True,
|
||||
})
|
||||
draft_payments = [p for l in lines for p in l.payments
|
||||
if p.state == 'draft']
|
||||
if draft_payments:
|
||||
Payment.delete(draft_payments)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def payment_unblock(cls, lines):
|
||||
cls.write(lines, {
|
||||
'payment_blocked': False,
|
||||
})
|
||||
|
||||
|
||||
class PayLineAskJournal(ModelView):
|
||||
'Pay Line'
|
||||
@@ -150,6 +183,13 @@ class PayLine(Wizard):
|
||||
])
|
||||
pay = StateAction('account_payment.act_payment_form')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(PayLine, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'blocked': 'The Line "%(line)s" is blocked.',
|
||||
})
|
||||
|
||||
def _get_journals(self):
|
||||
journals = {}
|
||||
for journal in getattr(self.ask_journal, 'journals', []):
|
||||
@@ -225,6 +265,11 @@ class PayLine(Wizard):
|
||||
|
||||
payments = []
|
||||
for line in lines:
|
||||
if line.payment_blocked:
|
||||
self.raise_user_warning('blocked:%s' % line,
|
||||
'blocked', {
|
||||
'line': line.rec_name,
|
||||
})
|
||||
payments.append(self.get_payment(line, journals))
|
||||
Payment.save(payments)
|
||||
return action, {
|
||||
|
||||
+22
@@ -17,6 +17,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="domain"
|
||||
eval="[('account.kind', 'in', ['receivable', 'payable']), ('party', '!=', None), ('reconciliation', '=', None), ('payment_amount', '!=', 0), ('move_state', '=', 'posted')]"
|
||||
pyson="1"/>
|
||||
<field name="search_value"
|
||||
eval="[('payment_blocked', '=', False)]" pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_move_line_form_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
@@ -82,6 +84,26 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="group" ref="group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="move_line_payment_block_button">
|
||||
<field name="name">payment_block</field>
|
||||
<field name="model" search="[('model', '=', 'account.move.line')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group"
|
||||
id="move_line_payment_block_button_group_payment">
|
||||
<field name="button" ref="move_line_payment_block_button"/>
|
||||
<field name="group" ref="group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.button" id="move_line_payment_unblock_button">
|
||||
<field name="name">payment_unblock</field>
|
||||
<field name="model" search="[('model', '=', 'account.move.line')]"/>
|
||||
</record>
|
||||
<record model="ir.model.button-res.group"
|
||||
id="move_line_payment_unblock_button_group_payment">
|
||||
<field name="button" ref="move_line_payment_unblock_button"/>
|
||||
<field name="group" ref="group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.property" id="property_payment_group_sequence">
|
||||
<field name="field"
|
||||
search="[('model.model', '=', 'account.configuration'), ('name', '=', 'payment_group_sequence')]"/>
|
||||
|
||||
@@ -106,3 +106,27 @@ Partially fail to pay the remaining::
|
||||
>>> line.reload()
|
||||
>>> line.payment_amount
|
||||
Decimal('30.00')
|
||||
|
||||
Pay line and block it after::
|
||||
|
||||
>>> move, = move.duplicate()
|
||||
>>> move.click('post')
|
||||
>>> line, = [l for l in move.lines if l.account == payable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.journal = payment_journal
|
||||
>>> pay_line.execute('start')
|
||||
>>> len(line.payments)
|
||||
1
|
||||
|
||||
>>> line.click('payment_block')
|
||||
>>> len(line.payments)
|
||||
0
|
||||
|
||||
Try to pay blocked line::
|
||||
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.form.journal = payment_journal
|
||||
>>> pay_line.execute('start') # doctest: +IGNORE_EXCEPTION_DETAIL
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
UserWarning: ...
|
||||
|
||||
@@ -13,6 +13,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="debit"/>
|
||||
<field name="credit"/>
|
||||
<field name="amount_second_currency"/>
|
||||
<field name="payment_blocked" tree_invisible="1"/>
|
||||
<button name="payment_block" string="Block"/>
|
||||
<button name="payment_unblock" string="Unblock"/>
|
||||
<field name="payment_kind" tree_invisible="1"/>
|
||||
<button name="pay" string="Pay Lines" tree_invisible="1"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user