diff --git a/CHANGELOG b/CHANGELOG index f2f6225810..fecd30c9a0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow processing receivable payment without approval +* Add submitted state to payment * Permit to edit amount for manual payment in processing * Use reference field for statement line relation * Do not create dunning for line with pending payment diff --git a/doc/index.rst b/doc/index.rst index 1b87c67c4c..b53d922431 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -31,7 +31,11 @@ The payment can be in one of this states: * Draft - The payment is waiting for approval. + The payment is in preparation. + +* Submitted + + The payment has been submitted and is waiting approval or to be processed. * Approved diff --git a/payment.py b/payment.py index b85a20b0cc..30b5428122 100644 --- a/payment.py +++ b/payment.py @@ -351,6 +351,9 @@ class Payment(Workflow, ModelSQL, ModelView): process_method = fields.Function( fields.Selection('get_process_methods', "Process Method"), 'on_change_with_process_method', searcher='search_process_method') + submitted_by = employee_field( + "Submitted by", + states=['submitted', 'processing', 'succeeded', 'failed']) approved_by = employee_field( "Approved by", states=['approved', 'processing', 'succeeded', 'failed']) @@ -361,11 +364,17 @@ class Payment(Workflow, ModelSQL, ModelView): states=['failed', 'processing']) state = fields.Selection([ ('draft', 'Draft'), + ('submitted', "Submitted"), ('approved', 'Approved'), ('processing', 'Processing'), ('succeeded', 'Succeeded'), ('failed', 'Failed'), - ], "State", readonly=True, select=True, sort=False) + ], "State", readonly=True, select=True, sort=False, + domain=[ + If(Eval('kind') == 'receivable', + ('state', '!=', 'approved'), + ()), + ]) @property def amount_line_paid(self): @@ -382,10 +391,13 @@ class Payment(Workflow, ModelSQL, ModelView): super(Payment, cls).__setup__() cls._order.insert(0, ('date', 'DESC')) cls._transitions |= set(( - ('draft', 'approved'), + ('draft', 'submitted'), + ('submitted', 'approved'), + ('submitted', 'processing'), ('approved', 'processing'), ('processing', 'succeeded'), ('processing', 'failed'), + ('submitted', 'draft'), ('approved', 'draft'), ('succeeded', 'failed'), ('succeeded', 'processing'), @@ -394,15 +406,22 @@ class Payment(Workflow, ModelSQL, ModelView): )) cls._buttons.update({ 'draft': { - 'invisible': Eval('state') != 'approved', + 'invisible': ~Eval('state').in_(['submitted', 'approved']), 'icon': 'tryton-back', 'depends': ['state'], }, - 'approve': { + 'submit': { 'invisible': Eval('state') != 'draft', 'icon': 'tryton-forward', 'depends': ['state'], }, + 'approve': { + 'invisible': ( + (Eval('state') != 'submitted') + | (Eval('kind') == 'receivable')), + 'icon': 'tryton-forward', + 'depends': ['state', 'kind'], + }, 'proceed': { 'invisible': ( ~Eval('state').in_(['succeeded', 'failed']) @@ -532,10 +551,17 @@ class Payment(Workflow, ModelSQL, ModelView): @classmethod @ModelView.button @Workflow.transition('draft') - @reset_employee('approved_by', 'succeeded_by', 'failed_by') + @reset_employee('submitted_by', 'approved_by', 'succeeded_by', 'failed_by') def draft(cls, payments): pass + @classmethod + @ModelView.button + @Workflow.transition('submitted') + @set_employee('submitted_by') + def submit(cls, payments): + pass + @classmethod @ModelView.button @Workflow.transition('approved') @@ -617,6 +643,11 @@ class ProcessPayment(Wizard): Warning = pool.get('res.user.warning') payments = self.records + payments = [ + p for p in payments + if p.state == 'approved' + or (p.state == 'submitted' and p.kind == 'receivable')] + for payment in payments: if payment.line and payment.line.payment_amount < 0: if Warning.check(str(payment)): diff --git a/payment.xml b/payment.xml index 63f97fa98f..19363f4612 100644 --- a/payment.xml +++ b/payment.xml @@ -236,29 +236,36 @@ this repository contains the full copyright notices and license terms. --> - - Approved + + To Approve - + + + + + + To Process + + Processing - + Succeeded - + Failed - + @@ -380,6 +387,16 @@ this repository contains the full copyright notices and license terms. --> + + submit + Submit + + + + + + + approve Approve diff --git a/tests/scenario_account_payment.rst b/tests/scenario_account_payment.rst index c4c0380389..c3a92176e0 100644 --- a/tests/scenario_account_payment.rst +++ b/tests/scenario_account_payment.rst @@ -93,6 +93,9 @@ Partially pay line:: >>> payment.amount Decimal('50.00') >>> payment.amount = Decimal('20.00') + >>> payment.click('submit') + >>> payment.submitted_by == employee + True >>> payment.click('approve') >>> payment.approved_by == employee True @@ -149,6 +152,7 @@ Partially fail to pay the remaining:: >>> payment, = Payment.find([('state', '=', 'draft')]) >>> payment.amount Decimal('30.00') + >>> payment.click('submit') >>> payment.click('approve') >>> process_payment = Wizard('account.payment.process', [payment]) >>> process_payment.execute('process') diff --git a/tests/scenario_account_payment_dunning.rst b/tests/scenario_account_payment_dunning.rst index ac48fcd914..ece4533339 100644 --- a/tests/scenario_account_payment_dunning.rst +++ b/tests/scenario_account_payment_dunning.rst @@ -98,7 +98,7 @@ Create no dunning:: Fail the payment:: - >>> payment.click('approve') + >>> payment.click('submit') >>> process_payment = Wizard('account.payment.process', [payment]) >>> process_payment.execute('process') >>> payment.click('fail') diff --git a/tests/scenario_account_payment_invoice.rst b/tests/scenario_account_payment_invoice.rst index 0bfaf0312b..f7b2aba5d0 100644 --- a/tests/scenario_account_payment_invoice.rst +++ b/tests/scenario_account_payment_invoice.rst @@ -80,7 +80,7 @@ Partially pay line:: >>> pay_line.execute('next_') >>> payment, = Payment.find() >>> payment.amount = Decimal('20') - >>> payment.click('approve') + >>> payment.click('submit') Check amount to pay:: @@ -121,7 +121,7 @@ Create multiple valid payments for one line:: >>> payments = Payment.find([('state', '=', 'draft')]) >>> for payment in payments: ... payment.amount = Decimal('30') - >>> Payment.click(payments, 'approve') + >>> Payment.click(payments, 'submit') Check amount to pay:: diff --git a/view/payment_form.xml b/view/payment_form.xml index bc078a52b7..1bd2af6fd7 100644 --- a/view/payment_form.xml +++ b/view/payment_form.xml @@ -27,6 +27,8 @@ this repository contains the full copyright notices and license terms. -->