mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 21:22:03 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -3,3 +3,4 @@
|
|||
from . import account_payment_register
|
||||
from . import payment_link_wizard
|
||||
from . import payment_refund_wizard
|
||||
from . import res_config_settings
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ class AccountPaymentRegister(models.TransientModel):
|
|||
use_electronic_payment_method = fields.Boolean(
|
||||
compute='_compute_use_electronic_payment_method',
|
||||
)
|
||||
payment_method_code = fields.Char(
|
||||
related='payment_method_line_id.code')
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# COMPUTE METHODS
|
||||
|
|
@ -35,21 +33,18 @@ class AccountPaymentRegister(models.TransientModel):
|
|||
@api.depends('payment_method_line_id')
|
||||
def _compute_suitable_payment_token_ids(self):
|
||||
for wizard in self:
|
||||
wizard.suitable_payment_token_ids = [Command.clear()]
|
||||
if wizard.can_edit_wizard and wizard.use_electronic_payment_method:
|
||||
related_partner_ids = (
|
||||
wizard.partner_id
|
||||
| wizard.partner_id.commercial_partner_id
|
||||
| wizard.partner_id.commercial_partner_id.child_ids
|
||||
)._origin
|
||||
|
||||
token_partners = wizard.partner_id
|
||||
lines_partners = wizard.batches[0]['lines'].move_id.partner_id
|
||||
if len(lines_partners) == 1:
|
||||
token_partners |= lines_partners
|
||||
wizard.suitable_payment_token_ids = self.env['payment.token'].sudo().search([
|
||||
('company_id', '=', wizard.company_id.id),
|
||||
*self.env['payment.token']._check_company_domain(wizard.company_id),
|
||||
('partner_id', 'in', token_partners.ids),
|
||||
('provider_id.capture_manually', '=', False),
|
||||
('partner_id', 'in', related_partner_ids.ids),
|
||||
('provider_id', '=', wizard.payment_method_line_id.payment_provider_id.id),
|
||||
])
|
||||
else:
|
||||
wizard.suitable_payment_token_ids = [Command.clear()]
|
||||
|
||||
@api.depends('payment_method_line_id')
|
||||
def _compute_use_electronic_payment_method(self):
|
||||
|
|
@ -59,28 +54,17 @@ class AccountPaymentRegister(models.TransientModel):
|
|||
codes = [key for key in dict(self.env['payment.provider']._fields['code']._description_selection(self.env))]
|
||||
wizard.use_electronic_payment_method = wizard.payment_method_code in codes
|
||||
|
||||
@api.onchange('can_edit_wizard', 'payment_method_line_id', 'journal_id')
|
||||
@api.depends('can_edit_wizard', 'suitable_payment_token_ids', 'journal_id')
|
||||
def _compute_payment_token_id(self):
|
||||
codes = [key for key in dict(self.env['payment.provider']._fields['code']._description_selection(self.env))]
|
||||
for wizard in self:
|
||||
related_partner_ids = (
|
||||
wizard.partner_id
|
||||
| wizard.partner_id.commercial_partner_id
|
||||
| wizard.partner_id.commercial_partner_id.child_ids
|
||||
)._origin
|
||||
if wizard.can_edit_wizard \
|
||||
and wizard.payment_method_line_id.code in codes \
|
||||
and wizard.journal_id \
|
||||
and related_partner_ids:
|
||||
|
||||
wizard.payment_token_id = self.env['payment.token'].sudo().search([
|
||||
('company_id', '=', wizard.company_id.id),
|
||||
('partner_id', 'in', related_partner_ids.ids),
|
||||
('provider_id.capture_manually', '=', False),
|
||||
('provider_id', '=', wizard.payment_method_line_id.payment_provider_id.id),
|
||||
], limit=1)
|
||||
else:
|
||||
if wizard.payment_method_line_id and wizard.payment_method_line_id.code not in codes:
|
||||
wizard.payment_token_id = False
|
||||
elif wizard.payment_token_id in wizard.suitable_payment_token_ids:
|
||||
# The selected payment token is still valid.
|
||||
continue
|
||||
else:
|
||||
wizard.payment_token_id = wizard.suitable_payment_token_ids[:1]
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# BUSINESS METHODS
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<field name="use_electronic_payment_method" invisible="1"/>
|
||||
<field name="payment_token_id"
|
||||
options="{'no_create': True}"
|
||||
attrs="{'invisible': ['|', ('use_electronic_payment_method', '!=', True), '|', ('can_edit_wizard', '=', False), '&', ('can_group_payments', '=', True), ('group_payment', '=', False)]}"/>
|
||||
invisible="not use_electronic_payment_method or not can_edit_wizard or (can_group_payments and not group_payment)"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
|
|
@ -1,26 +1,110 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.tools import format_date, formatLang, str2bool
|
||||
|
||||
from odoo.addons.payment import utils as payment_utils
|
||||
|
||||
|
||||
class PaymentLinkWizard(models.TransientModel):
|
||||
_inherit = 'payment.link.wizard'
|
||||
|
||||
def _get_additional_link_values(self):
|
||||
""" Override of `payment` to add `invoice_id` to the payment link values.
|
||||
invoice_amount_due = fields.Monetary(
|
||||
string="Amount Due",
|
||||
compute='_compute_invoice_amount_due',
|
||||
currency_field='currency_id'
|
||||
)
|
||||
open_installments = fields.Json(export_string_translation=False)
|
||||
open_installments_preview = fields.Html(
|
||||
export_string_translation=False, compute='_compute_open_installments_preview'
|
||||
)
|
||||
display_open_installments = fields.Boolean(compute='_compute_display_open_installments')
|
||||
has_eligible_epd = fields.Boolean()
|
||||
discount_date = fields.Date()
|
||||
epd_info = fields.Char(
|
||||
string="Early Payment Discount Information",
|
||||
compute='_compute_epd_info',
|
||||
)
|
||||
|
||||
The other values related to the invoice are directly read from the invoice.
|
||||
def _compute_warning_message(self):
|
||||
super()._compute_warning_message()
|
||||
for wizard in self:
|
||||
if not wizard.warning_message and not str2bool(self.env['ir.config_parameter'].sudo().get_param('account_payment.enable_portal_payment')):
|
||||
wizard.warning_message = _("Online payment option is not enabled in Configuration.")
|
||||
|
||||
Note: self.ensure_one()
|
||||
@api.depends('amount_max')
|
||||
def _compute_invoice_amount_due(self):
|
||||
for wizard in self:
|
||||
wizard.invoice_amount_due = wizard.amount_max
|
||||
|
||||
:return: The additional payment link values.
|
||||
:rtype: dict
|
||||
"""
|
||||
res = super()._get_additional_link_values()
|
||||
@api.depends('open_installments')
|
||||
def _compute_open_installments_preview(self):
|
||||
for wizard in self:
|
||||
preview = ""
|
||||
if wizard.display_open_installments:
|
||||
for installment in wizard.open_installments or []:
|
||||
preview += "<div>"
|
||||
preview += _(
|
||||
'#%(number)s - Installment of <strong>%(amount)s</strong> due on <strong class="text-primary">%(date)s</strong>',
|
||||
number=installment['number'],
|
||||
amount=formatLang(
|
||||
self.env,
|
||||
installment['amount'],
|
||||
currency_obj=wizard.currency_id,
|
||||
),
|
||||
date=installment['date_maturity'],
|
||||
)
|
||||
preview += "</div>"
|
||||
wizard.open_installments_preview = preview
|
||||
|
||||
@api.depends('amount')
|
||||
def _compute_epd_info(self):
|
||||
for wizard in self:
|
||||
wizard.epd_info = ''
|
||||
if wizard.has_eligible_epd and wizard.amount == wizard.invoice_amount_due:
|
||||
msg = _("A discount will be applied if the customer pays before %s included.", format_date(wizard.env, wizard.discount_date))
|
||||
wizard.epd_info = msg
|
||||
|
||||
@api.depends('open_installments')
|
||||
def _compute_display_open_installments(self):
|
||||
# hides the installments section if only one installment
|
||||
for wizard in self:
|
||||
installments = wizard.open_installments or []
|
||||
wizard.display_open_installments = len(installments) > 1
|
||||
|
||||
def _prepare_url(self, base_url, related_document):
|
||||
""" Override of `payment` to use the portal page URL. """
|
||||
res = super()._prepare_url(base_url, related_document)
|
||||
if self.res_model != 'account.move':
|
||||
return res
|
||||
|
||||
return f'{base_url}/{related_document.get_portal_url()}'
|
||||
|
||||
def _prepare_query_params(self, related_document):
|
||||
""" Override of `payment` to define custom query params for invoice payment. """
|
||||
res = super()._prepare_query_params(related_document)
|
||||
if self.res_model != 'account.move':
|
||||
return res
|
||||
|
||||
# Invoice-related fields are retrieved in the controller.
|
||||
return {
|
||||
'invoice_id': self.res_id,
|
||||
'move_id': related_document.id,
|
||||
'amount': self.amount,
|
||||
'payment_token': self._prepare_access_token(),
|
||||
'payment': True,
|
||||
}
|
||||
|
||||
def _prepare_access_token(self):
|
||||
""" Override of `payment` to generate the access token only based on the amount. """
|
||||
res = super()._prepare_access_token()
|
||||
if self.res_model != 'account.move':
|
||||
return res
|
||||
|
||||
return payment_utils.generate_access_token(self.res_id, self.amount, env=self.env)
|
||||
|
||||
def _prepare_anchor(self):
|
||||
""" Override of `payment` to set the 'portal_pay' anchor. """
|
||||
res = super()._prepare_anchor()
|
||||
if self.res_model != 'account.move':
|
||||
return res
|
||||
|
||||
return '#portal_pay'
|
||||
|
|
|
|||
|
|
@ -11,4 +11,37 @@
|
|||
<field name="binding_view_types">form</field>
|
||||
</record>
|
||||
|
||||
<record id="payment_link_wizard__form_inherit_account_payment" model="ir.ui.view">
|
||||
<field name="name">payment.link.wizard.form.inherit.account_payment</field>
|
||||
<field name="model">payment.link.wizard</field>
|
||||
<field name="inherit_id" ref="payment.payment_link_wizard_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
|
||||
<div name="no_partner_email" position="before">
|
||||
<field name="epd_info"
|
||||
class="alert alert-info fw-bold w-100 mb-3"
|
||||
role="alert"
|
||||
invisible="not epd_info"/>
|
||||
</div>
|
||||
|
||||
<field name="amount" position="after">
|
||||
<field name="invoice_amount_due" invisible="res_model != 'account.move'"/>
|
||||
</field>
|
||||
|
||||
<field name="currency_id" position="after">
|
||||
<field name="open_installments" invisible="1"/>
|
||||
</field>
|
||||
|
||||
<group name="payment_info" position="after">
|
||||
<group name="next_installments"
|
||||
string="Next Installments"
|
||||
invisible="not display_open_installments"
|
||||
class="mt-n4"
|
||||
>
|
||||
<field name="open_installments_preview" nolabel="1"/>
|
||||
</group>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ class PaymentRefundWizard(models.TransientModel):
|
|||
string="Refund Amount", compute='_compute_amount_to_refund', store=True, readonly=False
|
||||
)
|
||||
currency_id = fields.Many2one(string="Currency", related='transaction_id.currency_id')
|
||||
support_refund = fields.Selection(related='transaction_id.provider_id.support_refund')
|
||||
support_refund = fields.Selection(
|
||||
string="Refund",
|
||||
selection=[('none', "Unsupported"), ('full_only', "Full Only"), ('partial', "Partial")],
|
||||
compute='_compute_support_refund',
|
||||
)
|
||||
has_pending_refund = fields.Boolean(
|
||||
string="Has a pending refund", compute='_compute_has_pending_refund'
|
||||
)
|
||||
|
|
@ -51,6 +55,20 @@ class PaymentRefundWizard(models.TransientModel):
|
|||
for wizard in self:
|
||||
wizard.amount_to_refund = wizard.amount_available_for_refund
|
||||
|
||||
@api.depends('transaction_id.provider_id', 'transaction_id.payment_method_id')
|
||||
def _compute_support_refund(self):
|
||||
for wizard in self:
|
||||
tx_sudo = wizard.transaction_id.sudo() # needed for users without access to the provider
|
||||
p_support_refund = tx_sudo.provider_id.support_refund
|
||||
pm_sudo = tx_sudo.payment_method_id
|
||||
pm_support_refund = (pm_sudo.primary_payment_method_id or pm_sudo).support_refund
|
||||
if p_support_refund == 'none' or pm_support_refund == 'none':
|
||||
wizard.support_refund = 'none'
|
||||
elif p_support_refund == 'full_only' or pm_support_refund == 'full_only':
|
||||
wizard.support_refund = 'full_only'
|
||||
else: # Both support partial refunds.
|
||||
wizard.support_refund = 'partial'
|
||||
|
||||
@api.depends('payment_id') # To always trigger the compute
|
||||
def _compute_has_pending_refund(self):
|
||||
for wizard in self:
|
||||
|
|
@ -62,5 +80,5 @@ class PaymentRefundWizard(models.TransientModel):
|
|||
wizard.has_pending_refund = pending_refunds_count > 0
|
||||
|
||||
def action_refund(self):
|
||||
for wizard in self:
|
||||
wizard.transaction_id.action_refund(amount_to_refund=wizard.amount_to_refund)
|
||||
self.ensure_one()
|
||||
return self.transaction_id.action_refund(amount_to_refund=self.amount_to_refund)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<div class="alert alert-warning"
|
||||
id="alert_draft_refund_tx"
|
||||
role="alert"
|
||||
attrs="{'invisible': [('has_pending_refund', '=', False)]}">
|
||||
invisible="not has_pending_refund">
|
||||
<p>
|
||||
<strong>Warning!</strong> There is a refund pending for this payment.
|
||||
Wait a moment for it to be processed. If the refund is still pending in a
|
||||
|
|
@ -25,10 +25,10 @@
|
|||
<field name="support_refund" invisible="1"/>
|
||||
<field name="payment_amount"/>
|
||||
<field name="refunded_amount"
|
||||
attrs="{'invisible': [('refunded_amount', '<=', 0)]}"/>
|
||||
invisible="refunded_amount <= 0"/>
|
||||
<field name="amount_available_for_refund"/>
|
||||
<field name="amount_to_refund"
|
||||
attrs="{'readonly': [('support_refund', '=', 'full_only')]}"/>
|
||||
readonly="support_refund == 'full_only'"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
pay_invoices_online = fields.Boolean(config_parameter='account_payment.enable_portal_payment')
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.account</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="module_account_payment" position="replace">
|
||||
<field name="pay_invoices_online" string="Invoice Online Payment"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue