From 15d88d5bc10f6ff60e796f6a1859db9ae880090b Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 9 Jul 2018 16:39:21 -0700 Subject: [PATCH] Initial commit of Forte Payment integration and parts of `hr_payroll_payment` to support it. --- hr_payroll_payment/__manifest__.py | 2 +- .../hr_payroll_register_payment.py | 28 +++- .../hr_payroll_register_payment.xml | 5 + payment_forte/__init__.py | 1 + payment_forte/__manifest__.py | 14 ++ payment_forte/data/payment_acquirer_data.xml | 16 +++ payment_forte/models/__init__.py | 1 + payment_forte/models/forte_request.py | 81 +++++++++++ payment_forte/models/payment.py | 132 ++++++++++++++++++ payment_forte/tests/__init__.py | 1 + payment_forte/tests/test_forte.py | 45 ++++++ payment_forte/views/payment_views.xml | 33 +++++ 12 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 payment_forte/__init__.py create mode 100644 payment_forte/__manifest__.py create mode 100644 payment_forte/data/payment_acquirer_data.xml create mode 100644 payment_forte/models/__init__.py create mode 100644 payment_forte/models/forte_request.py create mode 100644 payment_forte/models/payment.py create mode 100644 payment_forte/tests/__init__.py create mode 100644 payment_forte/tests/test_forte.py create mode 100644 payment_forte/views/payment_views.xml diff --git a/hr_payroll_payment/__manifest__.py b/hr_payroll_payment/__manifest__.py index 8d5dce77..5c72f984 100755 --- a/hr_payroll_payment/__manifest__.py +++ b/hr_payroll_payment/__manifest__.py @@ -11,7 +11,7 @@ Adds the ability to register a payment on a payslip. """, 'website': 'https://hibou.io/', - 'depends': ['hr_payroll_account'], + 'depends': ['hr_payroll_account', 'payment'], 'data': [ 'hr_payroll_register_payment.xml', ], diff --git a/hr_payroll_payment/hr_payroll_register_payment.py b/hr_payroll_payment/hr_payroll_register_payment.py index 0c9f6cf9..3114702d 100755 --- a/hr_payroll_payment/hr_payroll_register_payment.py +++ b/hr_payroll_payment/hr_payroll_register_payment.py @@ -56,6 +56,12 @@ class HrPayrollRegisterPaymentWizard(models.TransientModel): journal_id = fields.Many2one('account.journal', string='Payment Method', required=True, domain=[('type', 'in', ('bank', 'cash'))]) company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', readonly=True, required=True) payment_method_id = fields.Many2one('account.payment.method', string='Payment Type', required=True) + payment_method_code = fields.Char(related='payment_method_id.code', + help="Technical field used to adapt the interface to the payment type selected.", readonly=True) + payment_transaction_id = fields.Many2one('payment.transaction', string="Payment Transaction") + payment_token_id = fields.Many2one('payment.token', string="Saved payment token", + domain=[('acquirer_id.capture_manually', '=', False)], + help="Note that tokens from acquirers set to only authorize transactions (instead of capturing the amount) are not available.") amount = fields.Monetary(string='Payment Amount', required=True, default=_default_amount) currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self.env.user.company_id.currency_id) payment_date = fields.Date(string='Payment Date', default=fields.Date.context_today, required=True) @@ -63,6 +69,24 @@ class HrPayrollRegisterPaymentWizard(models.TransientModel): hide_payment_method = fields.Boolean(compute='_compute_hide_payment_method', help="Technical field used to hide the payment method if the selected journal has only one available which is 'manual'") + @api.onchange('partner_id') + def _onchange_partner_id(self): + res = {} + if self.partner_id: + partners = self.partner_id | self.partner_id.commercial_partner_id | self.partner_id.commercial_partner_id.child_ids + res['domain'] = { + 'payment_token_id': [('partner_id', 'in', partners.ids), ('acquirer_id.capture_manually', '=', False)]} + + return res + + @api.onchange('payment_method_id', 'journal_id') + def _onchange_payment_method(self): + if self.payment_method_code == 'electronic': + self.payment_token_id = self.env['payment.token'].search( + [('partner_id', '=', self.partner_id.id), ('acquirer_id.capture_manually', '=', False)], limit=1) + else: + self.payment_token_id = False + @api.one @api.constrains('amount') def _check_amount(self): @@ -106,7 +130,9 @@ class HrPayrollRegisterPaymentWizard(models.TransientModel): 'amount': self.amount, 'currency_id': self.currency_id.id, 'payment_date': self.payment_date, - 'communication': self.communication + 'communication': self.communication, + 'payment_transaction_id': self.payment_transaction_id.id if self.payment_transaction_id else False, + 'payment_token_id': self.payment_token_id.id if self.payment_token_id else False, }) payment.post() diff --git a/hr_payroll_payment/hr_payroll_register_payment.xml b/hr_payroll_payment/hr_payroll_register_payment.xml index 44e2a0b8..f4aefb09 100755 --- a/hr_payroll_payment/hr_payroll_register_payment.xml +++ b/hr_payroll_payment/hr_payroll_register_payment.xml @@ -33,6 +33,10 @@ + +