mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MIG] account_payment_order: Migration to 15.0
This commit is contained in:
committed by
Pedro M. Baeza
parent
ed5c2d0c3f
commit
ad9f376b29
@@ -14,16 +14,20 @@ class AccountJournal(models.Model):
|
||||
compute="_compute_outbound_payment_order_only", readonly=True, store=True
|
||||
)
|
||||
|
||||
@api.depends("inbound_payment_method_ids.payment_order_only")
|
||||
@api.depends("inbound_payment_method_line_ids.payment_method_id.payment_order_only")
|
||||
def _compute_inbound_payment_order_only(self):
|
||||
for rec in self:
|
||||
rec.inbound_payment_order_only = all(
|
||||
p.payment_order_only for p in rec.inbound_payment_method_ids
|
||||
p.payment_order_only
|
||||
for p in rec.inbound_payment_method_line_ids.payment_method_id
|
||||
)
|
||||
|
||||
@api.depends("outbound_payment_method_ids.payment_order_only")
|
||||
@api.depends(
|
||||
"outbound_payment_method_line_ids.payment_method_id.payment_order_only"
|
||||
)
|
||||
def _compute_outbound_payment_order_only(self):
|
||||
for rec in self:
|
||||
rec.outbound_payment_order_only = all(
|
||||
p.payment_order_only for p in rec.outbound_payment_method_ids
|
||||
p.payment_order_only
|
||||
for p in rec.outbound_payment_method_line_ids.payment_method_id
|
||||
)
|
||||
|
||||
@@ -23,7 +23,6 @@ class AccountMove(models.Model):
|
||||
# payment mode or company level
|
||||
reference_type = fields.Selection(
|
||||
selection=[("none", "Free Reference"), ("structured", "Structured Reference")],
|
||||
string="Reference Type",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
default="none",
|
||||
@@ -102,18 +101,20 @@ class AccountMove(models.Model):
|
||||
if new_payorder:
|
||||
move.message_post(
|
||||
body=_(
|
||||
"%d payment lines added to the new draft payment "
|
||||
"order %s which has been automatically created."
|
||||
"%(count)d payment lines added to the new draft payment "
|
||||
"order %(name)s which has been automatically created.",
|
||||
count=count,
|
||||
name=payorder.name,
|
||||
)
|
||||
% (count, payorder.name)
|
||||
)
|
||||
else:
|
||||
move.message_post(
|
||||
body=_(
|
||||
"%d payment lines added to the existing draft "
|
||||
"payment order %s."
|
||||
"%(count)d payment lines added to the existing draft "
|
||||
"payment order %(name)s.",
|
||||
count=count,
|
||||
name=payorder.name,
|
||||
)
|
||||
% (count, payorder.name)
|
||||
)
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id(
|
||||
"account_payment_order.account_payment_order_%s_action"
|
||||
|
||||
@@ -11,29 +11,33 @@ class AccountPayment(models.Model):
|
||||
res = super()._get_default_journal()
|
||||
return res.filtered(lambda journal: not journal.inbound_payment_order_only)
|
||||
|
||||
@api.depends(
|
||||
"payment_type",
|
||||
"journal_id.inbound_payment_method_ids",
|
||||
"journal_id.outbound_payment_method_ids",
|
||||
)
|
||||
def _compute_payment_method_fields(self):
|
||||
res = super()._compute_payment_method_fields()
|
||||
@api.depends("payment_type", "journal_id")
|
||||
def _compute_payment_method_line_fields(self):
|
||||
res = super()._compute_payment_method_line_fields()
|
||||
for pay in self:
|
||||
if pay.payment_type == "inbound":
|
||||
pay.available_payment_method_ids = (
|
||||
pay.journal_id.inbound_payment_method_ids.filtered(
|
||||
lambda m: not m.payment_order_only
|
||||
)
|
||||
)
|
||||
else:
|
||||
pay.available_payment_method_ids = (
|
||||
pay.journal_id.outbound_payment_method_ids.filtered(
|
||||
lambda m: not m.payment_order_only
|
||||
)
|
||||
)
|
||||
|
||||
pay.hide_payment_method = (
|
||||
len(pay.available_payment_method_ids) == 1
|
||||
and pay.available_payment_method_ids.code == "manual"
|
||||
pay.available_payment_method_line_ids = (
|
||||
pay.journal_id._get_available_payment_method_lines(
|
||||
pay.payment_type
|
||||
).filtered(lambda x: not x.payment_method_id.payment_order_only)
|
||||
)
|
||||
to_exclude = self._get_payment_method_codes_to_exclude()
|
||||
if to_exclude:
|
||||
pay.available_payment_method_line_ids = (
|
||||
pay.available_payment_method_line_ids.filtered(
|
||||
lambda x: x.code not in to_exclude
|
||||
)
|
||||
)
|
||||
if (
|
||||
pay.payment_method_line_id.id
|
||||
not in pay.available_payment_method_line_ids.ids
|
||||
):
|
||||
# In some cases, we could be linked to a payment method
|
||||
# line that has been unlinked from the journal.
|
||||
# In such cases, we want to show it on the payment.
|
||||
pay.hide_payment_method_line = False
|
||||
else:
|
||||
pay.hide_payment_method_line = (
|
||||
len(pay.available_payment_method_line_ids) == 1
|
||||
and pay.available_payment_method_line_ids.code == "manual"
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -29,7 +29,6 @@ class AccountPaymentOrder(models.Model):
|
||||
)
|
||||
payment_type = fields.Selection(
|
||||
selection=[("inbound", "Inbound"), ("outbound", "Outbound")],
|
||||
string="Payment Type",
|
||||
readonly=True,
|
||||
required=True,
|
||||
)
|
||||
@@ -180,10 +179,11 @@ class AccountPaymentOrder(models.Model):
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The payment type (%s) is not the same as the payment "
|
||||
"type of the payment mode (%s)"
|
||||
"The payment type (%(ptype)s) is not the same as the payment "
|
||||
"type of the payment mode (%(pmode)s)",
|
||||
ptype=order.payment_type,
|
||||
pmode=order.payment_mode_id.payment_type,
|
||||
)
|
||||
% (order.payment_type, order.payment_mode_id.payment_type)
|
||||
)
|
||||
|
||||
@api.constrains("date_scheduled")
|
||||
@@ -194,10 +194,11 @@ class AccountPaymentOrder(models.Model):
|
||||
if order.date_scheduled < today:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On payment order %s, the Payment Execution Date "
|
||||
"is in the past (%s)."
|
||||
"On payment order %(porder)s, the Payment Execution Date "
|
||||
"is in the past (%(exedate)s).",
|
||||
porder=order.name,
|
||||
exedate=order.date_scheduled,
|
||||
)
|
||||
% (order.name, order.date_scheduled)
|
||||
)
|
||||
|
||||
@api.depends("payment_line_ids", "payment_line_ids.amount_company_currency")
|
||||
@@ -327,16 +328,14 @@ class AccountPaymentOrder(models.Model):
|
||||
):
|
||||
raise UserError(
|
||||
_(
|
||||
"The payment mode '%s' has the option "
|
||||
"The payment mode '%(pmode)s' has the option "
|
||||
"'Disallow Debit Before Maturity Date'. The "
|
||||
"payment line %s has a maturity date %s "
|
||||
"which is after the computed payment date %s."
|
||||
)
|
||||
% (
|
||||
order.payment_mode_id.name,
|
||||
payline.name,
|
||||
payline.ml_maturity_date,
|
||||
requested_date,
|
||||
"payment line %(pline)s has a maturity date %(mdate)s "
|
||||
"which is after the computed payment date %(pdate)s.",
|
||||
pmode=order.payment_mode_id.name,
|
||||
pline=payline.name,
|
||||
mdate=payline.ml_maturity_date,
|
||||
pdate=requested_date,
|
||||
)
|
||||
)
|
||||
# Write requested_date on 'date' field of payment line
|
||||
@@ -366,8 +365,12 @@ class AccountPaymentOrder(models.Model):
|
||||
# Block if a bank payment line is <= 0
|
||||
if paydict["total"] <= 0:
|
||||
raise UserError(
|
||||
_("The amount for Partner '%s' is negative " "or null (%.2f) !")
|
||||
% (paydict["paylines"][0].partner_id.name, paydict["total"])
|
||||
_(
|
||||
"The amount for Partner '%(partner)s' is negative "
|
||||
"or null (%(amount).2f) !",
|
||||
partner=paydict["paylines"][0].partner_id.name,
|
||||
amount=paydict["total"],
|
||||
)
|
||||
)
|
||||
vals = self._prepare_bank_payment_line(paydict["paylines"])
|
||||
bplo.create(vals)
|
||||
@@ -460,10 +463,22 @@ class AccountPaymentOrder(models.Model):
|
||||
self, amount_company_currency, amount_payment_currency, bank_lines
|
||||
):
|
||||
vals = {}
|
||||
if self.payment_type == "outbound":
|
||||
account_id = self.journal_id.payment_credit_account_id.id
|
||||
else:
|
||||
account_id = self.journal_id.payment_debit_account_id.id
|
||||
payment_method = self.payment_mode_id.payment_method_id
|
||||
account_id = False
|
||||
if self.payment_type == "inbound":
|
||||
account_id = (
|
||||
self.journal_id.inbound_payment_method_line_ids.filtered(
|
||||
lambda x: x.payment_method_id == payment_method
|
||||
).payment_account_id.id
|
||||
or self.journal_id.company_id.account_journal_payment_debit_account_id.id
|
||||
)
|
||||
elif self.payment_type == "outbound":
|
||||
account_id = (
|
||||
self.journal_id.outbound_payment_method_line_ids.filtered(
|
||||
lambda x: x.payment_method_id == payment_method
|
||||
).payment_account_id.id
|
||||
or self.journal_id.company_id.account_journal_payment_credit_account_id.id
|
||||
)
|
||||
|
||||
partner_id = False
|
||||
for index, bank_line in enumerate(bank_lines):
|
||||
|
||||
@@ -70,7 +70,7 @@ class BankPaymentLine(models.Model):
|
||||
communication_type = fields.Selection(
|
||||
related="payment_line_ids.communication_type", readonly=True
|
||||
)
|
||||
communication = fields.Char(string="Communication", required=True, readonly=True)
|
||||
communication = fields.Char(required=True, readonly=True)
|
||||
company_id = fields.Many2one(
|
||||
comodel_name="res.company",
|
||||
related="order_id.payment_mode_id.company_id",
|
||||
@@ -160,26 +160,29 @@ class BankPaymentLine(models.Model):
|
||||
raise UserError(
|
||||
_(
|
||||
"Can not reconcile: no move line for "
|
||||
"payment line %s of partner '%s'."
|
||||
"payment line %(line)s of partner '%(partner)s'.",
|
||||
line=payment_line.name,
|
||||
partner=payment_line.partner_id.name,
|
||||
)
|
||||
% (payment_line.name, payment_line.partner_id.name)
|
||||
)
|
||||
if payment_line.move_line_id.reconciled:
|
||||
raise UserError(
|
||||
_("Move line '%s' of partner '%s' has already " "been reconciled")
|
||||
% (payment_line.move_line_id.name, payment_line.partner_id.name)
|
||||
_(
|
||||
"Move line '%(line)s' of partner '%(partner)s' has already "
|
||||
"been reconciled",
|
||||
line=payment_line.move_line_id.name,
|
||||
partner=payment_line.partner_id.name,
|
||||
)
|
||||
)
|
||||
if payment_line.move_line_id.account_id != transit_mline.account_id:
|
||||
raise UserError(
|
||||
_(
|
||||
"For partner '%s', the account of the account "
|
||||
"move line to pay (%s) is different from the "
|
||||
"account of of the transit move line (%s)."
|
||||
)
|
||||
% (
|
||||
payment_line.move_line_id.partner_id.name,
|
||||
payment_line.move_line_id.account_id.code,
|
||||
transit_mline.account_id.code,
|
||||
"For partner '%(partner)s', the account of the account "
|
||||
"move line to pay (%(line1)s) is different from the "
|
||||
"account of of the transit move line (%(line2)s).",
|
||||
partner=payment_line.move_line_id.partner_id.name,
|
||||
line1=payment_line.move_line_id.account_id.code,
|
||||
line2=transit_mline.account_id.code,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -194,8 +197,8 @@ class BankPaymentLine(models.Model):
|
||||
raise UserError(
|
||||
_(
|
||||
"Cannot delete a payment order line whose payment order is"
|
||||
" in state '%s'. You need to cancel it first."
|
||||
" in state '%(state)s'. You need to cancel it first.",
|
||||
state=order_state,
|
||||
)
|
||||
% order_state
|
||||
)
|
||||
return super(BankPaymentLine, self).unlink()
|
||||
|
||||
@@ -14,10 +14,11 @@ class ResBank(models.Model):
|
||||
if bank.bic and len(bank.bic) not in (8, 11):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"A valid BIC contains 8 or 11 characters. The BIC '%s' "
|
||||
"contains %d characters, so it is not valid."
|
||||
"A valid BIC contains 8 or 11 characters. The BIC '%(bic)s' "
|
||||
"contains %(num)d characters, so it is not valid.",
|
||||
bic=bank.bic,
|
||||
num=len(bank.bic),
|
||||
)
|
||||
% (bank.bic, len(bank.bic))
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user