mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-24 11:22:07 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,9 +1,10 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class Paymentprovider(models.Model):
|
||||
|
||||
class PaymentProvider(models.Model):
|
||||
_inherit = 'payment.provider'
|
||||
|
||||
journal_id = fields.Many2one(
|
||||
|
|
@ -12,7 +13,8 @@ class Paymentprovider(models.Model):
|
|||
comodel_name='account.journal',
|
||||
compute='_compute_journal_id',
|
||||
inverse='_inverse_journal_id',
|
||||
domain='[("type", "=", "bank"), ("company_id", "=", company_id)]',
|
||||
check_company=True,
|
||||
domain='[("type", "=", "bank")]',
|
||||
copy=False,
|
||||
)
|
||||
|
||||
|
|
@ -23,10 +25,14 @@ class Paymentprovider(models.Model):
|
|||
if not self.id:
|
||||
return
|
||||
|
||||
pay_method_line = self.env['account.payment.method.line'].search(
|
||||
[('code', '=', self.code), ('payment_provider_id', '=', self.id)],
|
||||
limit=1,
|
||||
)
|
||||
default_payment_method = self._get_provider_payment_method(self._get_code())
|
||||
if not default_payment_method:
|
||||
return
|
||||
|
||||
pay_method_line = self.env['account.payment.method.line'].search([
|
||||
('payment_provider_id', '=', self.id),
|
||||
('journal_id', '!=', False),
|
||||
], limit=1)
|
||||
|
||||
if not self.journal_id:
|
||||
if pay_method_line:
|
||||
|
|
@ -36,9 +42,10 @@ class Paymentprovider(models.Model):
|
|||
if not pay_method_line:
|
||||
pay_method_line = self.env['account.payment.method.line'].search(
|
||||
[
|
||||
('company_id', '=', self.company_id.id),
|
||||
('code', '=', self.code),
|
||||
*self.env['account.payment.method.line']._check_company_domain(self.company_id),
|
||||
('code', '=', self._get_code()),
|
||||
('payment_provider_id', '=', False),
|
||||
('journal_id', '!=', False),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
|
|
@ -47,34 +54,44 @@ class Paymentprovider(models.Model):
|
|||
pay_method_line.journal_id = self.journal_id
|
||||
pay_method_line.name = self.name
|
||||
elif allow_create:
|
||||
default_payment_method_id = self._get_default_payment_method_id(self.code)
|
||||
if not default_payment_method_id:
|
||||
return
|
||||
|
||||
create_values = {
|
||||
'name': self.name,
|
||||
'payment_method_id': default_payment_method_id,
|
||||
'payment_method_id': default_payment_method.id,
|
||||
'journal_id': self.journal_id.id,
|
||||
'payment_provider_id': self.id,
|
||||
'payment_account_id': self._get_payment_method_outstanding_account_id(default_payment_method)
|
||||
}
|
||||
pay_method_line_same_code = self.env['account.payment.method.line'].search(
|
||||
[
|
||||
('company_id', '=', self.company_id.id),
|
||||
('code', '=', self.code),
|
||||
*self.env['account.payment.method.line']._check_company_domain(self.company_id),
|
||||
('code', '=', self._get_code()),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if pay_method_line_same_code:
|
||||
create_values['payment_account_id'] = pay_method_line_same_code.payment_account_id.id
|
||||
if self._get_code() == 'sepa_direct_debit':
|
||||
create_values['name'] = "Online SEPA"
|
||||
self.env['account.payment.method.line'].create(create_values)
|
||||
|
||||
def _get_payment_method_outstanding_account_id(self, payment_method_id):
|
||||
if self.code == 'custom':
|
||||
return False
|
||||
account_ref = 'account_journal_payment_debit_account_id' if payment_method_id.payment_type == 'inbound' else 'account_journal_payment_credit_account_id'
|
||||
chart_template = self.with_context(allowed_company_ids=self.company_id.root_id.ids).env['account.chart.template']
|
||||
outstanding_account_id = (
|
||||
chart_template.ref(account_ref, raise_if_not_found=False)
|
||||
or self.company_id.transfer_account_id
|
||||
).id
|
||||
return outstanding_account_id
|
||||
|
||||
@api.depends('code', 'state', 'company_id')
|
||||
def _compute_journal_id(self):
|
||||
for provider in self:
|
||||
pay_method_line = self.env['account.payment.method.line'].search(
|
||||
[('code', '=', provider.code), ('payment_provider_id', '=', provider._origin.id)],
|
||||
limit=1,
|
||||
)
|
||||
pay_method_line = self.env['account.payment.method.line'].search([
|
||||
('payment_provider_id', '=', provider._origin.id),
|
||||
('journal_id', '!=', False),
|
||||
], limit=1)
|
||||
|
||||
if pay_method_line:
|
||||
provider.journal_id = pay_method_line.journal_id
|
||||
|
|
@ -93,13 +110,6 @@ class Paymentprovider(models.Model):
|
|||
for provider in self:
|
||||
provider._ensure_payment_method_line()
|
||||
|
||||
@api.model
|
||||
def _get_default_payment_method_id(self, code):
|
||||
provider_payment_method = self._get_provider_payment_method(code)
|
||||
if provider_payment_method:
|
||||
return provider_payment_method.id
|
||||
return None
|
||||
|
||||
@api.model
|
||||
def _get_provider_payment_method(self, code):
|
||||
return self.env['account.payment.method'].search([('code', '=', code)], limit=1)
|
||||
|
|
@ -107,9 +117,9 @@ class Paymentprovider(models.Model):
|
|||
#=== BUSINESS METHODS ===#
|
||||
|
||||
@api.model
|
||||
def _setup_provider(self, code):
|
||||
def _setup_provider(self, code, **kwargs):
|
||||
""" Override of `payment` to create the payment method of the provider. """
|
||||
super()._setup_provider(code)
|
||||
super()._setup_provider(code, **kwargs)
|
||||
self._setup_payment_method(code)
|
||||
|
||||
@api.model
|
||||
|
|
@ -122,17 +132,16 @@ class Paymentprovider(models.Model):
|
|||
'payment_type': 'inbound',
|
||||
})
|
||||
|
||||
def _check_existing_payment_method_lines(self, payment_method):
|
||||
existing_payment_method_lines_count = \
|
||||
self.env['account.payment.method.line'].search_count([('payment_method_id', '=', \
|
||||
payment_method.id)], limit=1)
|
||||
return bool(existing_payment_method_lines_count)
|
||||
def _check_existing_payment(self, payment_method):
|
||||
existing_payment_count = self.env['account.payment'].search_count([('payment_method_id', '=', payment_method.id)], limit=1)
|
||||
return bool(existing_payment_count)
|
||||
|
||||
@api.model
|
||||
def _remove_provider(self, code):
|
||||
def _remove_provider(self, code, **kwargs):
|
||||
""" Override of `payment` to delete the payment method of the provider. """
|
||||
payment_method = self._get_provider_payment_method(code)
|
||||
if self._check_existing_payment_method_lines(payment_method):
|
||||
raise UserError(_("To uninstall this module, please remove first the corresponding payment method line in the incoming payments tab defined on the bank journal."))
|
||||
super()._remove_provider(code)
|
||||
# If the payment method is used by any payments, we block the uninstallation of the module.
|
||||
if self._check_existing_payment(payment_method):
|
||||
raise UserError(_("You cannot uninstall this module as payments using this payment method already exist."))
|
||||
super()._remove_provider(code, **kwargs)
|
||||
payment_method.unlink()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue