mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] account_payment_order: computation of sepa + remove done state + UI adjustments
- Improve computation of sepa on account.payment.order: check IBAN is in SEPA zone Update move line generation to get transfer account from bank journal Update payment mode configuration accordingly (3 fields removed) Several improvements in payment order tree and form view - Remove done state (migration script provided) - Don't set reference_type field on account.move required=True, because it causes a lot of problems in other modules that don't depend on this one. Setting it as required in the view is enough. - add optional="hide" on payment mode in invoice tree view - FIX crash when communication=null on payment line - payment_mode_id readonly when state != draft
This commit is contained in:
committed by
Pedro M. Baeza
parent
c7239bbc22
commit
dc8dd37f0e
@@ -24,7 +24,6 @@ class AccountMove(models.Model):
|
||||
reference_type = fields.Selection(
|
||||
selection=[("none", "Free Reference"), ("structured", "Structured Reference")],
|
||||
string="Reference Type",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
default="none",
|
||||
|
||||
@@ -68,7 +68,7 @@ class AccountPaymentLine(models.Model):
|
||||
)
|
||||
date = fields.Date(string="Payment Date")
|
||||
communication = fields.Char(
|
||||
required=True, help="Label of the payment that will be seen by the destinee"
|
||||
required=False, help="Label of the payment that will be seen by the destinee"
|
||||
)
|
||||
communication_type = fields.Selection(
|
||||
selection=[("normal", "Free")], required=True, default="normal"
|
||||
@@ -162,3 +162,5 @@ class AccountPaymentLine(models.Model):
|
||||
raise UserError(
|
||||
_("Missing Partner Bank Account on payment line %s") % self.name
|
||||
)
|
||||
if not self.communication:
|
||||
raise UserError(_("Communication is empty on payment line %s.") % self.name)
|
||||
|
||||
@@ -75,27 +75,6 @@ class AccountPaymentMode(models.Model):
|
||||
generate_move = fields.Boolean(
|
||||
string="Generate Accounting Entries On File Upload", default=True
|
||||
)
|
||||
offsetting_account = fields.Selection(
|
||||
selection=[
|
||||
("bank_account", "Bank Account"),
|
||||
("transfer_account", "Transfer Account"),
|
||||
],
|
||||
default="bank_account",
|
||||
)
|
||||
transfer_account_id = fields.Many2one(
|
||||
comodel_name="account.account",
|
||||
domain=[("reconcile", "=", True)],
|
||||
help="Pay off lines in 'file uploaded' payment orders with a move on "
|
||||
"this account. You can only select accounts "
|
||||
"that are marked for reconciliation",
|
||||
check_company=True,
|
||||
)
|
||||
transfer_journal_id = fields.Many2one(
|
||||
comodel_name="account.journal",
|
||||
help="Journal to write payment entries when confirming "
|
||||
"payment/debit orders of this mode",
|
||||
check_company=True,
|
||||
)
|
||||
move_option = fields.Selection(
|
||||
selection=[
|
||||
("date", "One move per payment date"),
|
||||
@@ -105,50 +84,17 @@ class AccountPaymentMode(models.Model):
|
||||
)
|
||||
post_move = fields.Boolean(default=True)
|
||||
|
||||
@api.constrains(
|
||||
"generate_move",
|
||||
"offsetting_account",
|
||||
"transfer_account_id",
|
||||
"transfer_journal_id",
|
||||
"move_option",
|
||||
)
|
||||
@api.constrains("generate_move", "move_option")
|
||||
def transfer_move_constrains(self):
|
||||
for mode in self:
|
||||
if mode.generate_move:
|
||||
if not mode.offsetting_account:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On the payment mode '%s', you must select an "
|
||||
"option for the 'Offsetting Account' parameter"
|
||||
)
|
||||
% mode.name
|
||||
)
|
||||
elif mode.offsetting_account == "transfer_account":
|
||||
if not mode.transfer_account_id:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On the payment mode '%s', you must "
|
||||
"select a value for the 'Transfer Account'."
|
||||
)
|
||||
% mode.name
|
||||
)
|
||||
if not mode.transfer_journal_id:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On the payment mode '%s', you must "
|
||||
"select a value for the 'Transfer Journal'."
|
||||
)
|
||||
% mode.name
|
||||
)
|
||||
if not mode.move_option:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On the payment mode '%s', you must "
|
||||
"choose an option for the 'Move Option' "
|
||||
"parameter."
|
||||
)
|
||||
% mode.name
|
||||
if mode.generate_move and not mode.move_option:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"On the payment mode '%s', you must "
|
||||
"choose an option for the 'Move Option' parameter."
|
||||
)
|
||||
% mode.name
|
||||
)
|
||||
|
||||
@api.onchange("payment_method_id")
|
||||
def payment_method_id_change(self):
|
||||
@@ -175,16 +121,6 @@ class AccountPaymentMode(models.Model):
|
||||
def generate_move_change(self):
|
||||
if self.generate_move:
|
||||
# default values
|
||||
self.offsetting_account = "bank_account"
|
||||
self.move_option = "date"
|
||||
else:
|
||||
self.offsetting_account = False
|
||||
self.transfer_account_id = False
|
||||
self.transfer_journal_id = False
|
||||
self.move_option = False
|
||||
|
||||
@api.onchange("offsetting_account")
|
||||
def offsetting_account_change(self):
|
||||
if self.offsetting_account == "bank_account":
|
||||
self.transfer_account_id = False
|
||||
self.transfer_journal_id = False
|
||||
|
||||
@@ -23,6 +23,7 @@ class AccountPaymentOrder(models.Model):
|
||||
required=True,
|
||||
ondelete="restrict",
|
||||
tracking=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
check_company=True,
|
||||
)
|
||||
@@ -74,7 +75,6 @@ class AccountPaymentOrder(models.Model):
|
||||
("open", "Confirmed"),
|
||||
("generated", "File Generated"),
|
||||
("uploaded", "File Uploaded"),
|
||||
("done", "Done"),
|
||||
("cancel", "Cancel"),
|
||||
],
|
||||
string="Status",
|
||||
@@ -106,7 +106,6 @@ class AccountPaymentOrder(models.Model):
|
||||
)
|
||||
date_generated = fields.Date(string="File Generation Date", readonly=True)
|
||||
date_uploaded = fields.Date(string="File Upload Date", readonly=True)
|
||||
date_done = fields.Date(string="Done Date", readonly=True)
|
||||
generated_user_id = fields.Many2one(
|
||||
comodel_name="res.users",
|
||||
string="Generated by",
|
||||
@@ -118,14 +117,14 @@ class AccountPaymentOrder(models.Model):
|
||||
payment_line_ids = fields.One2many(
|
||||
comodel_name="account.payment.line",
|
||||
inverse_name="order_id",
|
||||
string="Transaction Lines",
|
||||
string="Transactions",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
bank_line_ids = fields.One2many(
|
||||
comodel_name="bank.payment.line",
|
||||
inverse_name="order_id",
|
||||
string="Bank Payment Lines",
|
||||
string="Bank Transactions",
|
||||
readonly=True,
|
||||
help="The bank payment lines are used to generate the payment file. "
|
||||
"They are automatically created from transaction lines upon "
|
||||
@@ -138,7 +137,7 @@ class AccountPaymentOrder(models.Model):
|
||||
compute="_compute_total", store=True, currency_field="company_currency_id"
|
||||
)
|
||||
bank_line_count = fields.Integer(
|
||||
compute="_compute_bank_line_count", string="Number of Bank Lines"
|
||||
compute="_compute_bank_line_count", string="Number of Bank Transactions"
|
||||
)
|
||||
move_ids = fields.One2many(
|
||||
comodel_name="account.move",
|
||||
@@ -146,6 +145,9 @@ class AccountPaymentOrder(models.Model):
|
||||
string="Journal Entries",
|
||||
readonly=True,
|
||||
)
|
||||
move_count = fields.Integer(
|
||||
compute="_compute_move_count", string="Number of Journal Entries"
|
||||
)
|
||||
description = fields.Char()
|
||||
|
||||
@api.depends("payment_mode_id")
|
||||
@@ -210,6 +212,19 @@ class AccountPaymentOrder(models.Model):
|
||||
for order in self:
|
||||
order.bank_line_count = len(order.bank_line_ids)
|
||||
|
||||
@api.depends("move_ids")
|
||||
def _compute_move_count(self):
|
||||
rg_res = self.env["account.move"].read_group(
|
||||
[("payment_order_id", "in", self.ids)],
|
||||
["payment_order_id"],
|
||||
["payment_order_id"],
|
||||
)
|
||||
mapped_data = {
|
||||
x["payment_order_id"][0]: x["payment_order_id_count"] for x in rg_res
|
||||
}
|
||||
for order in self:
|
||||
order.move_count = mapped_data.get(order.id, 0)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get("name", "New") == "New":
|
||||
@@ -234,11 +249,7 @@ class AccountPaymentOrder(models.Model):
|
||||
if self.payment_mode_id.default_date_prefered:
|
||||
self.date_prefered = self.payment_mode_id.default_date_prefered
|
||||
|
||||
def action_done(self):
|
||||
self.write({"date_done": fields.Date.context_today(self), "state": "done"})
|
||||
return True
|
||||
|
||||
def action_done_cancel(self):
|
||||
def action_uploaded_cancel(self):
|
||||
for move in self.move_ids:
|
||||
move.button_cancel()
|
||||
for move_line in move.line_ids:
|
||||
@@ -420,27 +431,19 @@ class AccountPaymentOrder(models.Model):
|
||||
return True
|
||||
|
||||
def _prepare_move(self, bank_lines=None):
|
||||
move_date = False
|
||||
if self.payment_type == "outbound":
|
||||
ref = _("Payment order %s") % self.name
|
||||
else:
|
||||
ref = _("Debit order %s") % self.name
|
||||
if bank_lines and len(bank_lines) == 1:
|
||||
ref += " - " + bank_lines.name
|
||||
if self.payment_mode_id.offsetting_account == "bank_account":
|
||||
journal_id = self.journal_id.id
|
||||
if bank_lines:
|
||||
move_date = bank_lines[0].date
|
||||
elif self.payment_mode_id.offsetting_account == "transfer_account":
|
||||
journal_id = self.payment_mode_id.transfer_journal_id.id
|
||||
vals = {
|
||||
"journal_id": journal_id,
|
||||
"date": bank_lines[0].date,
|
||||
"journal_id": self.journal_id.id,
|
||||
"ref": ref,
|
||||
"payment_order_id": self.id,
|
||||
"line_ids": [],
|
||||
}
|
||||
if move_date:
|
||||
vals.update({"date": move_date})
|
||||
total_company_currency = total_payment_currency = 0
|
||||
for bline in bank_lines:
|
||||
total_company_currency += bline.amount_company_currency
|
||||
@@ -458,18 +461,10 @@ class AccountPaymentOrder(models.Model):
|
||||
):
|
||||
vals = {}
|
||||
if self.payment_type == "outbound":
|
||||
name = _("Payment order %s") % self.name
|
||||
account_id = self.journal_id.payment_credit_account_id.id
|
||||
else:
|
||||
name = _("Debit order %s") % self.name
|
||||
if self.payment_mode_id.offsetting_account == "bank_account":
|
||||
vals.update({"date": bank_lines[0].date})
|
||||
else:
|
||||
vals.update({"date_maturity": bank_lines[0].date})
|
||||
account_id = self.journal_id.payment_debit_account_id.id
|
||||
|
||||
if self.payment_mode_id.offsetting_account == "bank_account":
|
||||
account_id = self.journal_id.default_account_id.id
|
||||
elif self.payment_mode_id.offsetting_account == "transfer_account":
|
||||
account_id = self.payment_mode_id.transfer_account_id.id
|
||||
partner_id = False
|
||||
for index, bank_line in enumerate(bank_lines):
|
||||
if index == 0:
|
||||
@@ -480,7 +475,6 @@ class AccountPaymentOrder(models.Model):
|
||||
break
|
||||
vals.update(
|
||||
{
|
||||
"name": name,
|
||||
"partner_id": partner_id,
|
||||
"account_id": account_id,
|
||||
"credit": (
|
||||
@@ -586,10 +580,19 @@ class AccountPaymentOrder(models.Model):
|
||||
|
||||
def action_move_journal_line(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref("account.action_move_journal_line")
|
||||
action_dict = action.read()[0]
|
||||
action_dict["domain"] = [("id", "in", self.move_ids.ids)]
|
||||
action = self.env.ref("account.action_move_journal_line").sudo().read()[0]
|
||||
if self.move_count == 1:
|
||||
action.update(
|
||||
{
|
||||
"view_mode": "form,tree,kanban",
|
||||
"views": False,
|
||||
"view_id": False,
|
||||
"res_id": self.move_ids[0].id,
|
||||
}
|
||||
)
|
||||
else:
|
||||
action["domain"] = [("id", "in", self.move_ids.ids)]
|
||||
ctx = self.env.context.copy()
|
||||
ctx.update({"search_default_misc_filter": 0})
|
||||
action_dict["context"] = ctx
|
||||
return action_dict
|
||||
action["context"] = ctx
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user