Skip to content

Commit

Permalink
[FIX] website_sale_sepa_dd_payment: set payment_mode_id
Browse files Browse the repository at this point in the history
  • Loading branch information
remytms committed Nov 26, 2024
1 parent 28a1782 commit e2f23c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions website_sale_sepa_dd_payment/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def shop_payment(self, **post):
if request.httprequest.method == "POST":
order = request.website.sale_get_order()
order.sepa_dd_iban = request.params.get("sepa-dd-iban", "")
order.payment_mode_id = order.get_sepa_dd_payment_mode()
try:
order.with_context(send_email=True).action_confirm()
except ValidationError as err:
Expand Down
24 changes: 12 additions & 12 deletions website_sale_sepa_dd_payment/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ class SaleOrder(models.Model):

@api.depends("order_line", "payment_mode_id")
def _compute_allow_sepa_dd_payment(self):
"""Allow sepa direct debit payment if payment is already set or
if products accept this type of payment.
"""
payment_mode = self.env["account.payment.mode"].search(
[("payment_method_id.code", "=", "sepa_direct_debit")],
limit=1,
)
for order in self:
only_contracts = all(
only_allowed = all(
order.order_line.mapped("product_id").mapped("allow_sepa_dd_payment")
)
order.allow_sepa_dd_payment = (
payment_mode == order.payment_mode_id or only_contracts
)
order.allow_sepa_dd_payment = only_allowed

def get_sepa_dd_payment_mode(self):
return self.env["account.payment.mode"].search(
[("payment_method_id.code", "=", "sepa_direct_debit")],
limit=1,
)

def action_confirm(self):
self.create_sepa_dd_mandate()
sepa_dd_payment_mode = self.get_sepa_dd_payment_mode()
for order in self:
if order.payment_mode_id == sepa_dd_payment_mode:
order.create_sepa_dd_mandate()
return super().action_confirm()

def validate_sepa_dd_iban(self):
Expand Down

0 comments on commit e2f23c3

Please sign in to comment.