diff --git a/CHANGELOG b/CHANGELOG index 8a5e0a1226..d64cf0bd71 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add employee on payments for some states + Version 5.8.0 - 2020-11-02 * Bug fixes (see mercurial logs for details) * Remove support for Python 3.5 diff --git a/payment.py b/payment.py index e3dd82db31..bb6c4a5104 100644 --- a/payment.py +++ b/payment.py @@ -17,7 +17,8 @@ from trytond.transaction import Transaction from trytond.tools import sortable_values from trytond.wizard import Wizard, StateView, StateAction, Button from trytond.pool import Pool - +from trytond.modules.company.model import ( + employee_field, set_employee, reset_employee) from .exceptions import OverpayWarning KINDS = [ @@ -311,6 +312,14 @@ 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') + approved_by = employee_field( + "Approved by", + states=['approved', 'processing', 'succeeded', 'failed']) + succeeded_by = employee_field( + "Success Noted by", states=['succeeded', 'processing']) + failed_by = employee_field( + "Failure Noted by", + states=['failed', 'processing']) state = fields.Selection([ ('draft', 'Draft'), ('approved', 'Approved'), @@ -446,6 +455,9 @@ class Payment(Workflow, ModelSQL, ModelView): else: default = default.copy() default.setdefault('group', None) + default.setdefault('approved_by') + default.setdefault('succeeded_by') + default.setdefault('failed_by') return super().copy(payments, default=default) @classmethod @@ -460,12 +472,14 @@ class Payment(Workflow, ModelSQL, ModelView): @classmethod @ModelView.button @Workflow.transition('draft') + @reset_employee('approved_by', 'succeeded_by', 'failed_by') def draft(cls, payments): pass @classmethod @ModelView.button @Workflow.transition('approved') + @set_employee('approved_by') def approve(cls, payments): pass @@ -497,12 +511,14 @@ class Payment(Workflow, ModelSQL, ModelView): @classmethod @ModelView.button @Workflow.transition('succeeded') + @set_employee('succeeded_by') def succeed(cls, payments): pass @classmethod @ModelView.button @Workflow.transition('failed') + @set_employee('failed_by') def fail(cls, payments): pass diff --git a/tests/scenario_account_payment.rst b/tests/scenario_account_payment.rst index c4f068e3b3..f9d20733ac 100644 --- a/tests/scenario_account_payment.rst +++ b/tests/scenario_account_payment.rst @@ -22,6 +22,20 @@ Create company:: >>> _ = create_company() >>> company = get_company() +Set employee:: + + >>> User = Model.get('res.user') + >>> Party = Model.get('party.party') + >>> Employee = Model.get('company.employee') + >>> employee_party = Party(name="Employee") + >>> employee_party.save() + >>> employee = Employee(party=employee_party) + >>> employee.save() + >>> user = User(config.user) + >>> user.employees.append(employee) + >>> user.employee = employee + >>> user.save() + Create fiscal year:: >>> fiscalyear = create_fiscalyear(company) @@ -46,7 +60,6 @@ Create payment journal:: Create parties:: - >>> Party = Model.get('party.party') >>> customer = Party(name='Customer') >>> customer.save() >>> supplier = Party(name='Supplier') @@ -81,6 +94,8 @@ Partially pay line:: Decimal('50.00') >>> payment.amount = Decimal('20.00') >>> payment.click('approve') + >>> payment.approved_by == employee + True >>> payment.state 'approved' >>> process_payment = Wizard('account.payment.process', [payment]) @@ -106,6 +121,8 @@ Check the properties of the payment group:: Success the payment and recheck the payment group:: >>> payment.click('succeed') + >>> payment.succeeded_by == employee + True >>> payment.state 'succeeded' >>> group.reload() @@ -139,6 +156,8 @@ Partially fail to pay the remaining:: Decimal('0.00') >>> payment.reload() >>> payment.click('fail') + >>> payment.failed_by == employee + True >>> payment.state 'failed' >>> payment.group.payment_complete diff --git a/view/payment_form.xml b/view/payment_form.xml index b4f8996a10..552b6f5d9e 100644 --- a/view/payment_form.xml +++ b/view/payment_form.xml @@ -28,6 +28,13 @@ this repository contains the full copyright notices and license terms. -->