diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/payment_fix_register_token | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/payment_fix_register_token')
6 files changed, 174 insertions, 0 deletions
diff --git a/addons/payment_fix_register_token/__init__.py b/addons/payment_fix_register_token/__init__.py new file mode 100644 index 00000000..cde864ba --- /dev/null +++ b/addons/payment_fix_register_token/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/addons/payment_fix_register_token/__manifest__.py b/addons/payment_fix_register_token/__manifest__.py new file mode 100644 index 00000000..554e52fe --- /dev/null +++ b/addons/payment_fix_register_token/__manifest__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': "Fix register payment wizard with 'payment' module", + 'category': 'Hidden', + 'version': '1.0', + 'description': """""", + 'depends': ['payment'], + 'data': [ + 'views/account_payment_register_views.xml', + ], + 'installable': True, + 'auto_install': True, + 'license': 'LGPL-3', +} diff --git a/addons/payment_fix_register_token/i18n/payment_fix_register_token.pot b/addons/payment_fix_register_token/i18n/payment_fix_register_token.pot new file mode 100644 index 00000000..c11479d3 --- /dev/null +++ b/addons/payment_fix_register_token/i18n/payment_fix_register_token.pot @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * payment_fix_register_token +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-10-22 06:08+0000\n" +"PO-Revision-Date: 2020-10-22 06:08+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register__payment_method_code +msgid "Code" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register__display_name +msgid "Display Name" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register__id +msgid "ID" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register____last_update +msgid "Last Modified on" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,help:payment_fix_register_token.field_account_payment_register__payment_token_id +msgid "" +"Note that tokens from acquirers set to only authorize transactions (instead " +"of capturing the amount) are not available." +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model,name:payment_fix_register_token.model_account_payment_register +msgid "Register Payment" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register__payment_token_id +msgid "Saved payment token" +msgstr "" + +#. module: payment_fix_register_token +#: model:ir.model.fields,field_description:payment_fix_register_token.field_account_payment_register__suitable_payment_token_partner_ids +msgid "Suitable Payment Token Partner" +msgstr "" diff --git a/addons/payment_fix_register_token/models/__init__.py b/addons/payment_fix_register_token/models/__init__.py new file mode 100644 index 00000000..5f7620e1 --- /dev/null +++ b/addons/payment_fix_register_token/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import account_payment_register diff --git a/addons/payment_fix_register_token/models/account_payment_register.py b/addons/payment_fix_register_token/models/account_payment_register.py new file mode 100644 index 00000000..09359ea3 --- /dev/null +++ b/addons/payment_fix_register_token/models/account_payment_register.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api, _ + + +class AccountPaymentRegister(models.TransientModel): + _inherit = 'account.payment.register' + + # == Business fields == + payment_token_id = fields.Many2one( + comodel_name='payment.token', + string="Saved payment token", + store=True, readonly=False, + compute='_compute_payment_token_id', + domain='''[ + (payment_method_code == 'electronic', '=', 1), + ('company_id', '=', company_id), + ('acquirer_id.capture_manually', '=', False), + ('acquirer_id.journal_id', '=', journal_id), + ('partner_id', 'in', suitable_payment_token_partner_ids), + ]''', + help="Note that tokens from acquirers set to only authorize transactions (instead of capturing the amount) are " + "not available.") + + # == Display purpose fields == + suitable_payment_token_partner_ids = fields.Many2many( + comodel_name='res.partner', + compute='_compute_suitable_payment_token_partner_ids') + payment_method_code = fields.Char( + related='payment_method_id.code') + + # ------------------------------------------------------------------------- + # COMPUTE METHODS + # ------------------------------------------------------------------------- + + @api.depends('can_edit_wizard') + def _compute_suitable_payment_token_partner_ids(self): + for wizard in self: + if wizard.can_edit_wizard: + lines = wizard._get_batches()[0]['lines'] + partners = lines.partner_id + commercial_partners = partners.commercial_partner_id + children_partners = commercial_partners.child_ids + wizard.suitable_payment_token_partner_ids = (partners + commercial_partners + children_partners)._origin + else: + wizard.suitable_payment_token_partner_ids = False + + @api.onchange('can_edit_wizard', 'payment_method_id', 'journal_id') + def _compute_payment_token_id(self): + for wizard in self: + if wizard.can_edit_wizard \ + and wizard.payment_method_id.code == 'electronic' \ + and wizard.journal_id \ + and wizard.suitable_payment_token_partner_ids: + wizard.payment_token_id = self.env['payment.token'].search([ + ('partner_id', 'in', wizard.suitable_payment_token_partner_ids.ids), + ('acquirer_id.capture_manually', '=', False), + ('acquirer_id.journal_id', '=', wizard.journal_id.id), + ], limit=1) + else: + wizard.payment_token_id = False + + # ------------------------------------------------------------------------- + # BUSINESS METHODS + # ------------------------------------------------------------------------- + + def _create_payment_vals_from_wizard(self): + # OVERRIDE + payment_vals = super()._create_payment_vals_from_wizard() + payment_vals['payment_token_id'] = self.payment_token_id.id + return payment_vals diff --git a/addons/payment_fix_register_token/views/account_payment_register_views.xml b/addons/payment_fix_register_token/views/account_payment_register_views.xml new file mode 100644 index 00000000..989eed10 --- /dev/null +++ b/addons/payment_fix_register_token/views/account_payment_register_views.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data> + + <record id="view_account_payment_register_form_inherit_payment" model="ir.ui.view"> + <field name="name">account.payment.register.form.inherit.payment</field> + <field name="model">account.payment.register</field> + <field name="inherit_id" ref="account.view_account_payment_register_form"/> + <field name="arch" type="xml"> + <field name="payment_method_id" position="after"> + <!-- Invisible fields --> + <field name="payment_method_code" invisible="1"/> + <field name="suitable_payment_token_partner_ids" invisible="1"/> + + <field name="payment_token_id" + options="{'no_create': True}" + attrs="{'invisible': ['|', ('payment_method_code', '!=', 'electronic'), '|', ('can_edit_wizard', '=', False), '&', ('can_group_payments', '=', True), ('group_payment', '=', False)]}"/> + </field> + </field> + </record> + + </data> +</odoo> |
