Collect by SEPA direct debit list,form code 0 ) if not rec_lines: skipped["no_line"] += 1 continue for line in rec_lines: partner = line.partner_id if not partner: skipped["no_partner"] += 1 continue if PaymentLine.search_count( [("move_line_id", "=", line.id), ("order_id.state", "!=", "cancel")] ): skipped["already"] += 1 continue if not Mandate.search_count( [("partner_id", "=", partner.commercial_partner_id.id), ("state", "=", "valid")] ): skipped["no_mandate"] += 1 continue partner_mode = partner.customer_payment_mode_id mode = partner_mode if is_sepa_inbound(partner_mode) else fallback_mode if not mode: skipped["no_mode"] += 1 continue lines_by_mode.setdefault(mode.id, env["account.move.line"]) lines_by_mode[mode.id] |= line # --- Create one draft payment order per payment mode and add the lines --- created_lines = 0 order_names = [] for mode_id, move_lines in lines_by_mode.items(): payment_order = Order.search( [("payment_mode_id", "=", mode_id), ("state", "=", "draft")], limit=1 ) if not payment_order: payment_order = Order.create({"payment_mode_id": mode_id}) move_lines.create_payment_line_from_move_line(payment_order) created_lines += len(move_lines) order_names.append(payment_order.name or "Draft") # --- Report --- message = ( "Payment lines created: %(created)s\n" "Payment order(s): %(orders)s\n\n" "Skipped:\n" " session without accounting move: %(no_move)s\n" " session without open receivable line: %(no_line)s\n" " line without partner: %(no_partner)s\n" " already in a payment order: %(already)s\n" " no valid SEPA mandate: %(no_mandate)s\n" " no SEPA payment mode: %(no_mode)s" ) % { "created": created_lines, "orders": ", ".join(order_names) or "-", "no_move": skipped["no_move"], "no_line": skipped["no_line"], "no_partner": skipped["no_partner"], "already": skipped["already"], "no_mandate": skipped["no_mandate"], "no_mode": skipped["no_mode"], } action = { "type": "ir.actions.client", "tag": "display_notification", "params": { "title": "SEPA collection", "message": message, "type": "success" if created_lines else "warning", "sticky": True, }, } ]]>