[ADD]pms: multiproperty payment acquirers adaptation

This commit is contained in:
Darío Lodeiros
2022-11-19 20:04:15 +01:00
parent 5002b9acf5
commit 6a043b0228
20 changed files with 48 additions and 619 deletions

View File

@@ -95,6 +95,7 @@
"report/proforma_report_templates.xml",
"report/proforma_report.xml",
"views/account_portal_templates.xml",
"views/payment_acquirer_views.xml",
],
"demo": [
"demo/pms_master_data.xml",

View File

@@ -4,6 +4,7 @@ from odoo import _, fields, http, tools
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.addons.account.controllers.portal import PortalAccount
from odoo.addons.payment.controllers.portal import PaymentProcessing
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
from odoo.addons.portal.models.portal_mixin import PortalMixin
@@ -31,6 +32,14 @@ class PortalFolio(CustomerPortal):
payment_inputs = request.env["payment.acquirer"]._get_available_payment_input(
partner=folio.partner_id, company=folio.company_id
)
acquirers = payment_inputs.get("acquirers")
for acquirer in acquirers:
if (
acquirer.pms_property_ids
and folio.pms_property_id.id not in acquirer.pms_property_ids.ids
):
payment_inputs["acquirers"] -= acquirer
values.update(payment_inputs)
is_public_user = request.env.user._is_public()
if is_public_user:
payment_inputs.pop("pms", None)
@@ -41,6 +50,13 @@ class PortalFolio(CustomerPortal):
[
("acquirer_id.company_id", "=", folio.company_id.id),
("partner_id", "=", folio.partner_id.id),
"|",
(
"acquirer_id.pms_property_ids",
"in",
folio.pms_property_id.id,
),
("acquirer_id.pms_property_ids", "=", False),
]
)
)
@@ -612,7 +628,7 @@ class PortalPrecheckin(CustomerPortal):
checkin_partner.send_portal_invitation_email(firstname, email)
class PortalAccount(CustomerPortal):
class PortalAccount(PortalAccount):
@http.route(
["/my/invoices/proforma/<int:invoice_id>"],
type="http",
@@ -648,3 +664,23 @@ class PortalAccount(CustomerPortal):
invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id
)
return request.render("pms.pms_proforma_invoice_template", values)
def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
"""
Override to add the pms property filter
"""
values = super(PortalAccount, self)._invoice_get_page_view_values(
invoice, access_token, **kwargs
)
acquirers = values.get("acquirers")
for acquirer in acquirers:
if (
acquirer.pms_property_ids
and invoice.pms_property_id.id not in acquirer.pms_property_ids.ids
):
values["acquirers"] -= acquirer
payment_tokens = values.get("payment_tokens")
for pms in payment_tokens:
if pms.acquirer_id not in values["acquirers"].ids:
values["pms"] -= pms
return values

View File

@@ -49,3 +49,4 @@ from . import payment_transaction
from . import res_partner_id_category
from . import pms_team_member
from . import ir_pms_property
from . import payment_acquirer

View File

@@ -0,0 +1,21 @@
# Copyright 2009-2020 Noviat
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class PaymentAcquirer(models.Model):
_inherit = "payment.acquirer"
_check_pms_properties_auto = True
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="pms_acquirer_property_rel",
column1="acquirer_id",
column2="property_id",
check_pms_properties=True,
)

View File

@@ -1,4 +1,4 @@
from odoo import _, fields, models
from odoo import _, api, fields, models
class PaymentTransaction(models.Model):
@@ -23,7 +23,6 @@ class PaymentTransaction(models.Model):
return super(PaymentTransaction, self)._create_payment(add_payment_vals)
def render_folio_button(self, folio, submit_txt=None, render_values=None):
self.reference = folio.name
values = {
"partner_id": folio.partner_id.id,
"type": self.type,
@@ -42,3 +41,11 @@ class PaymentTransaction(models.Model):
values=values,
)
)
@api.model
def _compute_reference_prefix(self, values):
res = super(PaymentTransaction, self)._compute_reference_prefix(values)
if not res and values and values.get("folio_ids"):
folios = self.new({"folio_ids": values["folio_ids"]}).folio_ids
return ",".join(folios.mapped("name"))
return None

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="payment_acquirer_form" model="ir.ui.view">
<field name="name">muliproperty.payment.acquirer.form</field>
<field name="model">payment.acquirer</field>
<field name="inherit_id" ref="payment.acquirer_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="pms_property_ids" widget="many2many_tags" />
</field>
</field>
</record>
</odoo>