94 lines
4.8 KiB
Python
94 lines
4.8 KiB
Python
from odoo import models, api
|
|
|
|
|
|
class AccountPaymentRegister(models.TransientModel):
|
|
_inherit = 'account.payment.register'
|
|
|
|
@api.depends('payment_type', 'partner_type')
|
|
def _compute_available_journal_ids(self):
|
|
"""
|
|
Override to include misc journals for vendor payments in the register payment wizard
|
|
"""
|
|
# Call the parent method to get the original computation with bank/cash journals
|
|
super()._compute_available_journal_ids()
|
|
|
|
# Then extend with general journals for supplier payments
|
|
for pay in self:
|
|
if pay.partner_type == 'supplier':
|
|
# Include all general journals for supplier payments
|
|
all_general_journals = self.env['account.journal'].search([
|
|
'|',
|
|
('company_id', 'parent_of', self.env.company.id),
|
|
('company_id', 'child_of', self.env.company.id),
|
|
('type', '=', 'general'),
|
|
])
|
|
|
|
pay.available_journal_ids |= all_general_journals
|
|
|
|
@api.depends('payment_type', 'journal_id', 'currency_id')
|
|
def _compute_payment_method_line_fields(self):
|
|
"""
|
|
Override to include payment methods for general journals in register payment wizard
|
|
"""
|
|
for pay in self:
|
|
available_payment_method_lines = pay.journal_id._get_available_payment_method_lines(pay.payment_type)
|
|
|
|
# For general journals, if no payment methods are available, provide defaults
|
|
if pay.journal_id.type == 'general' and not available_payment_method_lines:
|
|
# Get the manual payment methods (these work with general journals)
|
|
if pay.payment_type == 'outbound':
|
|
manual_out = self.env.ref('account.account_payment_method_manual_out', raise_if_not_found=False)
|
|
if manual_out:
|
|
# Create a payment method line for this journal if it doesn't exist
|
|
method_line = self.env['account.payment.method.line'].search([
|
|
('journal_id', '=', pay.journal_id.id),
|
|
('payment_method_id', '=', manual_out.id)
|
|
], limit=1)
|
|
|
|
if not method_line:
|
|
method_line = self.env['account.payment.method.line'].create({
|
|
'name': 'Manual (Outbound)',
|
|
'payment_method_id': manual_out.id,
|
|
'journal_id': pay.journal_id.id,
|
|
})
|
|
|
|
available_payment_method_lines = method_line
|
|
elif pay.payment_type == 'inbound':
|
|
manual_in = self.env.ref('account.account_payment_method_manual_in', raise_if_not_found=False)
|
|
if manual_in:
|
|
# Create a payment method line for this journal if it doesn't exist
|
|
method_line = self.env['account.payment.method.line'].search([
|
|
('journal_id', '=', pay.journal_id.id),
|
|
('payment_method_id', '=', manual_in.id)
|
|
], limit=1)
|
|
|
|
if not method_line:
|
|
method_line = self.env['account.payment.method.line'].create({
|
|
'name': 'Manual (Inbound)',
|
|
'payment_method_id': manual_in.id,
|
|
'journal_id': pay.journal_id.id,
|
|
})
|
|
|
|
available_payment_method_lines = method_line
|
|
|
|
pay.available_payment_method_line_ids = available_payment_method_lines
|
|
# Note: account.payment.register doesn't have _get_payment_method_codes_to_exclude method
|
|
# So we skip the exclusion logic for this model
|
|
|
|
@api.depends('available_payment_method_line_ids')
|
|
def _compute_payment_method_line_id(self):
|
|
"""
|
|
Override to ensure payment method is selected for general journals in register payment wizard
|
|
"""
|
|
for pay in self:
|
|
available_payment_method_lines = pay.available_payment_method_line_ids
|
|
|
|
# Select the first available one by default.
|
|
if pay.payment_method_line_id in available_payment_method_lines:
|
|
pay.payment_method_line_id = pay.payment_method_line_id
|
|
elif available_payment_method_lines:
|
|
pay.payment_method_line_id = available_payment_method_lines[0]._origin
|
|
else:
|
|
# For general journals, we might need to handle this differently
|
|
# But we'll let the constraint handle validation
|
|
pay.payment_method_line_id = False |