[REF] sale: adapt to payment changes
This commit is contained in:
@@ -10,7 +10,11 @@
|
||||
'description': """
|
||||
This module contains all the common features of Sales Management and eCommerce.
|
||||
""",
|
||||
'depends': ['sales_team', 'payment', 'portal', 'utm'],
|
||||
'depends': [
|
||||
'sales_team',
|
||||
'account_payment', # -> account, payment, portal
|
||||
'utm',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'security/res_groups.xml',
|
||||
|
||||
@@ -1297,6 +1297,16 @@ class SaleOrder(models.Model):
|
||||
|
||||
return self.order_line.filtered(show_line)
|
||||
|
||||
def _get_default_payment_link_values(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'description': self.name,
|
||||
'amount': self.amount_total - sum(self.invoice_ids.filtered(lambda x: x.state != 'cancel').mapped('amount_total')),
|
||||
'currency_id': self.currency_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'amount_max': self.amount_total,
|
||||
}
|
||||
|
||||
# PORTAL #
|
||||
|
||||
def _has_to_be_signed(self, include_draft=False):
|
||||
|
||||
@@ -5,12 +5,13 @@ from odoo.fields import Command
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.account_payment.tests.common import AccountPaymentCommon
|
||||
from odoo.addons.payment.tests.http_common import PaymentHttpCommon
|
||||
from odoo.addons.sale.tests.common import SaleCommon
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestSalePayment(SaleCommon, PaymentHttpCommon):
|
||||
class TestSalePayment(AccountPaymentCommon, SaleCommon, PaymentHttpCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
@@ -10,20 +10,6 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
_inherit = 'payment.link.wizard'
|
||||
_description = 'Generate Sales Payment Link'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super().default_get(fields)
|
||||
if res['res_id'] and res['res_model'] == 'sale.order':
|
||||
record = self.env[res['res_model']].browse(res['res_id'])
|
||||
res.update({
|
||||
'description': record.name,
|
||||
'amount': record.amount_total - sum(record.invoice_ids.filtered(lambda x: x.state != 'cancel').mapped('amount_total')),
|
||||
'currency_id': record.currency_id.id,
|
||||
'partner_id': record.partner_id.id,
|
||||
'amount_max': record.amount_total
|
||||
})
|
||||
return res
|
||||
|
||||
def _get_payment_acquirer_available(self, res_model, res_id, **kwargs):
|
||||
""" Select and return the acquirers matching the criteria.
|
||||
|
||||
@@ -36,19 +22,12 @@ class PaymentLinkWizard(models.TransientModel):
|
||||
kwargs['sale_order_id'] = res_id
|
||||
return super()._get_payment_acquirer_available(**kwargs)
|
||||
|
||||
def _generate_link(self):
|
||||
""" Override of payment to add the sale_order_id in the link. """
|
||||
for payment_link in self:
|
||||
# The sale_order_id field only makes sense if the document is a sales order
|
||||
if payment_link.res_model == 'sale.order':
|
||||
related_document = self.env[payment_link.res_model].browse(payment_link.res_id)
|
||||
base_url = related_document.get_base_url()
|
||||
payment_link.link = f'{base_url}/payment/pay' \
|
||||
f'?reference={urls.url_quote(payment_link.description)}' \
|
||||
f'&amount={payment_link.amount}' \
|
||||
f'&sale_order_id={payment_link.res_id}' \
|
||||
f'{"&acquirer_id=" + str(payment_link.payment_acquirer_selection) if payment_link.payment_acquirer_selection != "all" else "" }' \
|
||||
f'&access_token={payment_link.access_token}'
|
||||
# Order-related fields are retrieved in the controller
|
||||
else:
|
||||
super(PaymentLinkWizard, payment_link)._generate_link()
|
||||
def _get_additional_link_values(self):
|
||||
res = super()._get_additional_link_values()
|
||||
if self.res_model != 'sale.order':
|
||||
return res
|
||||
|
||||
# Order-related fields are retrieved in the controller
|
||||
return {
|
||||
'sale_order_id': self.res_id,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user