19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:07 +01:00
parent ba20ce7443
commit 768b70e05e
2357 changed files with 1057103 additions and 712486 deletions

View file

@ -12,7 +12,7 @@ class AccountPayment(models.Model):
string="Payment Transaction",
comodel_name='payment.transaction',
readonly=True,
auto_join=True, # No access rule bypass since access to payments means access to txs too
bypass_search_access=True, # No access rule bypass since access to payments means access to txs too
)
payment_token_id = fields.Many2one(
string="Saved Payment Token", comodel_name='payment.token', domain="""[
@ -49,7 +49,16 @@ class AccountPayment(models.Model):
def _compute_amount_available_for_refund(self):
for payment in self:
tx_sudo = payment.payment_transaction_id.sudo()
if tx_sudo.provider_id.support_refund and tx_sudo.operation != 'refund':
payment_method = (
tx_sudo.payment_method_id.primary_payment_method_id
or tx_sudo.payment_method_id
)
if (
tx_sudo # The payment was created by a transaction.
and tx_sudo.provider_id.support_refund != 'none'
and payment_method.support_refund != 'none'
and tx_sudo.operation != 'refund'
):
# Only consider refund transactions that are confirmed by summing the amounts of
# payments linked to such refund transactions. Indeed, should a refund transaction
# be stuck forever in a transient state (due to webhook failure, for example), the
@ -63,17 +72,11 @@ class AccountPayment(models.Model):
@api.depends('payment_method_line_id')
def _compute_suitable_payment_token_ids(self):
for payment in self:
related_partner_ids = (
payment.partner_id
| payment.partner_id.commercial_partner_id
| payment.partner_id.commercial_partner_id.child_ids
)._origin
if payment.use_electronic_payment_method:
payment.suitable_payment_token_ids = self.env['payment.token'].sudo().search([
('company_id', '=', payment.company_id.id),
*self.env['payment.token']._check_company_domain(payment.company_id),
('provider_id.capture_manually', '=', False),
('partner_id', 'in', related_partner_ids.ids),
('partner_id', '=', payment.partner_id.id),
('provider_id', '=', payment.payment_method_line_id.payment_provider_id.id),
])
else:
@ -93,10 +96,10 @@ class AccountPayment(models.Model):
('source_payment_id', 'in', self.ids),
('payment_transaction_id.operation', '=', 'refund')
],
fields=['source_payment_id'],
groupby=['source_payment_id']
groupby=['source_payment_id'],
aggregates=['__count']
)
data = {x['source_payment_id'][0]: x['source_payment_id_count'] for x in rg_data}
data = {source_payment.id: count for source_payment, count in rg_data}
for payment in self:
payment.refunds_count = data.get(payment.id, 0)
@ -109,18 +112,12 @@ class AccountPayment(models.Model):
self.payment_token_id = False
return
related_partner_ids = (
self.partner_id
| self.partner_id.commercial_partner_id
| self.partner_id.commercial_partner_id.child_ids
)._origin
self.payment_token_id = self.env['payment.token'].sudo().search([
('company_id', '=', self.company_id.id),
('partner_id', 'in', related_partner_ids.ids),
*self.env['payment.token']._check_company_domain(self.company_id),
('partner_id', '=', self.partner_id.id),
('provider_id.capture_manually', '=', False),
('provider_id', '=', self.payment_method_line_id.payment_provider_id.id),
], limit=1)
], limit=1) # In sudo mode to read the provider fields.
#=== ACTION METHODS ===#
@ -138,10 +135,10 @@ class AccountPayment(models.Model):
res = super(AccountPayment, self - payments_need_tx).action_post()
for tx in transactions: # Process the transactions with a payment by token
tx._send_payment_request()
tx._charge_with_token()
# Post payments for issued transactions
transactions._finalize_post_processing()
transactions._post_process()
payments_tx_done = payments_need_tx.filtered(
lambda p: p.payment_transaction_id.state == 'done'
)
@ -177,7 +174,7 @@ class AccountPayment(models.Model):
action['res_id'] = refund_tx.id
action['view_mode'] = 'form'
else:
action['view_mode'] = 'tree,form'
action['view_mode'] = 'list,form'
action['domain'] = [('source_payment_id', '=', self.id)]
return action
@ -203,10 +200,17 @@ class AccountPayment(models.Model):
def _prepare_payment_transaction_vals(self, **extra_create_values):
self.ensure_one()
if self.env.context.get('active_model', '') == 'account.move':
invoice_ids = self.env.context.get('active_ids', [])
elif self.env.context.get('active_model', '') == 'account.move.line':
invoice_ids = self.env['account.move.line'].browse(self.env.context.get('active_ids')).move_id.ids
else:
invoice_ids = []
return {
'provider_id': self.payment_token_id.provider_id.id,
'payment_method_id': self.payment_token_id.payment_method_id.id,
'reference': self.env['payment.transaction']._compute_reference(
self.payment_token_id.provider_id.code, prefix=self.ref
self.payment_token_id.provider_id.code, prefix=self.memo
),
'amount': self.amount,
'currency_id': self.currency_id.id,
@ -214,10 +218,7 @@ class AccountPayment(models.Model):
'token_id': self.payment_token_id.id,
'operation': 'offline',
'payment_id': self.id,
**({'invoice_ids': [Command.set(self._context.get('active_ids', []))]}
if self._context.get('active_model') == 'account.move'
else {}),
**extra_create_values,
'invoice_ids': [Command.set(invoice_ids)],
}
def _get_payment_refund_wizard_values(self):