feat: hide authorizer for rental orders, auto-set sale type
Rental orders no longer show the "Authorizer Required?" question or the Authorizer field. The sale type is automatically set to 'Rentals' when creating or confirming a rental order. Validation logic also skips authorizer checks for rental sale type. Made-with: Cursor
This commit is contained in:
@@ -42,6 +42,11 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
required=True,
|
||||
domain="[('code', '=', 'poynt'), ('state', '!=', 'disabled')]",
|
||||
)
|
||||
provider_name = fields.Char(
|
||||
related='provider_id.name',
|
||||
string="Poynt Provider",
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
payment_mode = fields.Selection(
|
||||
selection=[
|
||||
@@ -109,7 +114,7 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
res['amount'] = invoice.amount_residual
|
||||
res['currency_id'] = invoice.currency_id.id
|
||||
|
||||
provider = self.env['payment.provider'].search([
|
||||
provider = self.env['payment.provider'].sudo().search([
|
||||
('code', '=', 'poynt'),
|
||||
('state', '!=', 'disabled'),
|
||||
], limit=1)
|
||||
@@ -120,10 +125,15 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
|
||||
return res
|
||||
|
||||
def _get_provider_sudo(self):
|
||||
return self.provider_id.sudo()
|
||||
|
||||
@api.onchange('provider_id')
|
||||
def _onchange_provider_id(self):
|
||||
if self.provider_id and self.provider_id.poynt_default_terminal_id:
|
||||
self.terminal_id = self.provider_id.poynt_default_terminal_id
|
||||
if self.provider_id:
|
||||
provider = self._get_provider_sudo()
|
||||
if provider.poynt_default_terminal_id:
|
||||
self.terminal_id = provider.poynt_default_terminal_id
|
||||
|
||||
def action_collect_payment(self):
|
||||
"""Dispatch to the appropriate payment method."""
|
||||
@@ -213,7 +223,8 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
},
|
||||
}
|
||||
|
||||
action = 'AUTHORIZE' if self.provider_id.capture_manually else 'SALE'
|
||||
provider = self._get_provider_sudo()
|
||||
action = 'AUTHORIZE' if provider.capture_manually else 'SALE'
|
||||
minor_amount = poynt_utils.format_poynt_amount(
|
||||
self.amount, self.currency_id,
|
||||
)
|
||||
@@ -232,7 +243,7 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
'source': 'WEB',
|
||||
'sourceApp': 'odoo.fusion_poynt',
|
||||
'transactionInstruction': 'ONLINE_AUTH_REQUIRED',
|
||||
'businessId': self.provider_id.poynt_business_id,
|
||||
'businessId': provider.poynt_business_id,
|
||||
},
|
||||
'notes': reference,
|
||||
}
|
||||
@@ -243,7 +254,7 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
'type': 'POYNT_ORDER',
|
||||
}]
|
||||
|
||||
result = self.provider_id._poynt_make_request(
|
||||
result = provider._poynt_make_request(
|
||||
'POST', 'transactions', payload=txn_payload,
|
||||
)
|
||||
|
||||
@@ -303,7 +314,7 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
if not terminal:
|
||||
raise UserError(_("No terminal associated with this payment."))
|
||||
|
||||
provider = self.provider_id
|
||||
provider = self._get_provider_sudo()
|
||||
|
||||
try:
|
||||
txn = self._find_terminal_transaction(provider)
|
||||
@@ -517,14 +528,15 @@ class PoyntPaymentWizard(models.TransientModel):
|
||||
|
||||
def _create_poynt_order(self, reference):
|
||||
"""Create a Poynt order via the API."""
|
||||
provider = self._get_provider_sudo()
|
||||
order_payload = poynt_utils.build_order_payload(
|
||||
reference,
|
||||
self.amount,
|
||||
self.currency_id,
|
||||
business_id=self.provider_id.poynt_business_id,
|
||||
store_id=self.provider_id.poynt_store_id or '',
|
||||
business_id=provider.poynt_business_id,
|
||||
store_id=provider.poynt_store_id or '',
|
||||
)
|
||||
return self.provider_id._poynt_make_request(
|
||||
return provider._poynt_make_request(
|
||||
'POST', 'orders', payload=order_payload,
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<form string="Collect Poynt Payment">
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="poynt_transaction_ref" invisible="1"/>
|
||||
<field name="provider_id" invisible="1"/>
|
||||
|
||||
<!-- Status banner for waiting / done / error -->
|
||||
<div class="alert alert-info" role="alert"
|
||||
@@ -34,8 +35,7 @@
|
||||
<field name="partner_id"/>
|
||||
<field name="amount"/>
|
||||
<field name="currency_id"/>
|
||||
<field name="provider_id"
|
||||
readonly="state != 'draft'"/>
|
||||
<field name="provider_name"/>
|
||||
</group>
|
||||
<group string="Payment Mode"
|
||||
invisible="state not in ('draft', 'error')">
|
||||
|
||||
@@ -51,6 +51,11 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
required=True,
|
||||
readonly=True,
|
||||
)
|
||||
provider_name = fields.Char(
|
||||
related='provider_id.name',
|
||||
string="Poynt Provider",
|
||||
readonly=True,
|
||||
)
|
||||
original_transaction_id = fields.Many2one(
|
||||
'payment.transaction',
|
||||
string="Original Transaction",
|
||||
@@ -104,6 +109,9 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
)
|
||||
status_message = fields.Text(string="Status", readonly=True)
|
||||
|
||||
def _get_provider_sudo(self):
|
||||
return self.provider_id.sudo()
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
@@ -130,8 +138,9 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
res['original_invoice_id'] = credit_note.reversed_entry_id.id
|
||||
res['original_poynt_txn_id'] = orig_tx.poynt_transaction_id
|
||||
|
||||
if orig_tx.provider_id.poynt_default_terminal_id:
|
||||
res['terminal_id'] = orig_tx.provider_id.poynt_default_terminal_id.id
|
||||
provider = orig_tx.provider_id.sudo()
|
||||
if provider.poynt_default_terminal_id:
|
||||
res['terminal_id'] = provider.poynt_default_terminal_id.id
|
||||
|
||||
age_days = 0
|
||||
if orig_tx.create_date:
|
||||
@@ -201,7 +210,7 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
still showing ``status: CAPTURED``. We must check the full chain.
|
||||
"""
|
||||
orig_tx = self.original_transaction_id
|
||||
provider = self.provider_id
|
||||
provider = self._get_provider_sudo()
|
||||
txn_id = orig_tx.poynt_transaction_id
|
||||
|
||||
try:
|
||||
@@ -278,7 +287,7 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
def _process_referenced_refund(self):
|
||||
"""Send a referenced REFUND using the original transaction's parentId."""
|
||||
orig_tx = self.original_transaction_id
|
||||
provider = self.provider_id
|
||||
provider = self._get_provider_sudo()
|
||||
|
||||
parent_txn_id = orig_tx.poynt_transaction_id
|
||||
try:
|
||||
@@ -346,7 +355,7 @@ class PoyntRefundWizard(models.TransientModel):
|
||||
"The customer's card must be present on the device."
|
||||
))
|
||||
|
||||
provider = self.provider_id
|
||||
provider = self._get_provider_sudo()
|
||||
orig_tx = self.original_transaction_id
|
||||
minor_amount = poynt_utils.format_poynt_amount(
|
||||
self.amount, self.currency_id,
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
<field name="currency_id" invisible="1"/>
|
||||
</group>
|
||||
<group string="Original Payment">
|
||||
<field name="provider_id" readonly="1"/>
|
||||
<field name="provider_id" invisible="1"/>
|
||||
<field name="provider_name"/>
|
||||
<field name="original_transaction_id" readonly="1"/>
|
||||
<field name="original_poynt_txn_id" readonly="1"/>
|
||||
<field name="card_info" readonly="1"
|
||||
|
||||
Reference in New Issue
Block a user