diff --git a/sale_advance_payment/wizard/sale_advance_payment_wzd.py b/sale_advance_payment/wizard/sale_advance_payment_wzd.py
index 7177b672863..0af202b9e0e 100644
--- a/sale_advance_payment/wizard/sale_advance_payment_wzd.py
+++ b/sale_advance_payment/wizard/sale_advance_payment_wzd.py
@@ -18,6 +18,30 @@ class AccountVoucherWizard(models.TransientModel):
required=True,
domain=[("type", "in", ("bank", "cash"))],
)
+ payment_method_line_id = fields.Many2one(
+ "account.payment.method.line",
+ string="Payment Method",
+ readonly=False,
+ store=True,
+ copy=False,
+ compute="_compute_payment_method_line_id",
+ domain="[('id', 'in', available_payment_method_line_ids)]",
+ help="Manual: Pay or Get paid by any method outside of Odoo.\n"
+ "Payment Providers: Each payment provider has its own Payment Method. "
+ "Request a transaction on/to a card thanks to a payment token saved "
+ "by the partner when buying or subscribing online.\n"
+ "Check: Pay bills by check and print it from Odoo.\n"
+ "Batch Deposit: Collect several customer checks at once generating and "
+ "submitting a batch deposit to your bank. Module account_batch_payment "
+ "is necessary.\n"
+ "SEPA Credit Transfer: Pay in the SEPA zone by submitting a SEPA "
+ "Credit Transfer file to your bank. Module account_sepa is necessary.\n"
+ "SEPA Direct Debit: Get paid in the SEPA zone thanks to a mandate your "
+ "partner will have granted to you. Module account_sepa is necessary.\n",
+ )
+ available_payment_method_line_ids = fields.Many2many(
+ "account.payment.method.line", compute="_compute_payment_method_line_fields"
+ )
journal_currency_id = fields.Many2one(
"res.currency",
"Journal Currency",
@@ -44,6 +68,40 @@ class AccountVoucherWizard(models.TransientModel):
required=True,
)
+ @api.depends("available_payment_method_line_ids")
+ def _compute_payment_method_line_id(self):
+ """Compute the 'payment_method_line_id' field.
+ This field is not computed in '_compute_payment_method_line_fields'
+ because it's a stored editable one.
+ """
+ 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:
+ pay.payment_method_line_id = False
+
+ @api.depends("payment_type", "journal_id", "currency_id")
+ def _compute_payment_method_line_fields(self):
+ for pay in self:
+ pay.available_payment_method_line_ids = (
+ pay.journal_id._get_available_payment_method_lines(pay.payment_type)
+ )
+ to_exclude = pay._get_payment_method_codes_to_exclude()
+ if to_exclude:
+ pay.available_payment_method_line_ids = (
+ pay.available_payment_method_line_ids.filtered(
+ lambda line, to_exclude=to_exclude: line.code not in to_exclude
+ )
+ )
+
+ def _get_payment_method_codes_to_exclude(self):
+ return []
+
@api.depends("journal_id")
def _compute_get_journal_currency(self):
for wzd in self:
@@ -143,9 +201,7 @@ def _prepare_payment_vals(self, sale):
"journal_id": self.journal_id.id,
"currency_id": self.journal_currency_id.id,
"partner_id": partner_id,
- "payment_method_id": self.env.ref(
- "account.account_payment_method_manual_in"
- ).id,
+ "payment_method_line_id": self.payment_method_line_id.id,
}
def make_advance_payment(self):
diff --git a/sale_advance_payment/wizard/sale_advance_payment_wzd_view.xml b/sale_advance_payment/wizard/sale_advance_payment_wzd_view.xml
index cc2adf7b985..4702cced649 100644
--- a/sale_advance_payment/wizard/sale_advance_payment_wzd_view.xml
+++ b/sale_advance_payment/wizard/sale_advance_payment_wzd_view.xml
@@ -6,6 +6,7 @@
form